Module: Sneakers

Extended by:
Sneakers
Included in:
Sneakers
Defined in:
lib/sneakers/cli.rb,
lib/sneakers.rb,
lib/sneakers.rb,
lib/sneakers/errors.rb,
lib/sneakers/runner.rb,
lib/sneakers/worker.rb,
lib/sneakers/spawner.rb,
lib/sneakers/version.rb,
lib/sneakers/publisher.rb,
lib/sneakers/workergroup.rb,
lib/sneakers/content_type.rb,
lib/sneakers/configuration.rb,
lib/sneakers/error_reporter.rb,
lib/sneakers/concerns/logging.rb,
lib/sneakers/concerns/metrics.rb,
lib/sneakers/content_encoding.rb,
lib/sneakers/handlers/oneshot.rb,
lib/sneakers/handlers/maxretry.rb,
lib/sneakers/middleware/config.rb,
lib/sneakers/metrics/null_metrics.rb,
lib/sneakers/metrics/statsd_metrics.rb,
lib/sneakers/metrics/logging_metrics.rb,
lib/sneakers/metrics/newrelic_metrics.rb,
lib/sneakers/support/production_formatter.rb

Overview

Defined Under Namespace

Modules: Concerns, ErrorReporter, Handlers, Metrics, Middleware, Support, Worker, WorkerGroup Classes: CLI, Configuration, ContentEncoding, ContentType, Publisher, Queue, Runner, RunnerConfig, Spawner, Utils

Constant Summary collapse

CONFIG =
Configuration.new
VERSION =
"3.1.1"

Instance Method Summary collapse

Instance Method Details

#clear!Object



42
43
44
45
46
47
# File 'lib/sneakers.rb', line 42

def clear!
  CONFIG.clear
  @logger = nil
  @publisher = nil
  @configured = false
end

#configure(opts = {}) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/sneakers.rb', line 33

def configure(opts={})
  # worker > userland > defaults
  CONFIG.merge!(opts)
  setup_general_logger!
  setup_worker_concerns!
  setup_general_publisher!
  @configured = true
end

#configure_server {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Sneakers)

    the object that the method was called on



88
89
90
# File 'lib/sneakers.rb', line 88

def configure_server
  yield self if server?
end

#configured?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/sneakers.rb', line 76

def configured?
  @configured
end

#daemonize!(loglevel = Logger::INFO) ⇒ Object



49
50
51
52
53
54
# File 'lib/sneakers.rb', line 49

def daemonize!(loglevel=Logger::INFO)
  CONFIG[:log] = 'sneakers.log'
  CONFIG[:daemonize] = true
  setup_general_logger!
  logger.level = loglevel
end

#error_reportersObject

Register a proc to handle any error which occurs within the Sneakers process.

Sneakers.error_reporters << proc { |exception, worker, context_hash| MyErrorService.notify(exception, context_hash) }

The default error handler logs errors to Sneakers.logger. Ripped off from github.com/mperham/sidekiq/blob/6ad6a3aa330deebd76c6cf0d353f66abd3bef93b/lib/sidekiq.rb#L165-L174



98
99
100
# File 'lib/sneakers.rb', line 98

def error_reporters
  CONFIG[:error_reporters]
end

#loggerObject



68
69
70
# File 'lib/sneakers.rb', line 68

def logger
  @logger
end

#logger=(logger) ⇒ Object



64
65
66
# File 'lib/sneakers.rb', line 64

def logger=(logger)
  @logger = logger
end

#middlewareObject



102
103
104
# File 'lib/sneakers.rb', line 102

def middleware
  @middleware ||= Sneakers::Middleware::Config
end

#publish(msg, routing) ⇒ Object



72
73
74
# File 'lib/sneakers.rb', line 72

def publish(msg, routing)
  @publisher.publish(msg, routing)
end

#rake_worker_classesObject



60
61
62
# File 'lib/sneakers.rb', line 60

def rake_worker_classes
  @rake_worker_classes
end

#rake_worker_classes=(worker_classes) ⇒ Object



56
57
58
# File 'lib/sneakers.rb', line 56

def rake_worker_classes=(worker_classes)
  @rake_worker_classes = worker_classes
end

#server=(server) ⇒ Object



80
81
82
# File 'lib/sneakers.rb', line 80

def server=(server)
  @server = server
end

#server?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/sneakers.rb', line 84

def server?
  @server
end