Module: Nsqcd

Extended by:
Nsqcd
Included in:
Nsqcd
Defined in:
lib/nsqcd.rb,
lib/nsqcd.rb,
lib/nsqcd/errors.rb,
lib/nsqcd/runner.rb,
lib/nsqcd/worker.rb,
lib/nsqcd/version.rb,
lib/nsqcd/workergroup.rb,
lib/nsqcd/configuration.rb,
lib/nsqcd/error_reporter.rb,
lib/nsqcd/concerns/logging.rb,
lib/nsqcd/concerns/metrics.rb,
lib/nsqcd/support/production_formatter.rb

Defined Under Namespace

Modules: Concerns, ErrorReporter, Handlers, Support, Worker, WorkerGroup Classes: Configuration, Queue, Runner, RunnerConfig, Utils

Constant Summary collapse

CONFIG =
Configuration.new
VERSION =
"0.1.0"

Instance Method Summary collapse

Instance Method Details

#clear!Object



31
32
33
34
35
# File 'lib/nsqcd.rb', line 31

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

#configure(opts = {}) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/nsqcd.rb', line 23

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

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

Yields:

  • (_self)

Yield Parameters:

  • _self (Nsqcd)

    the object that the method was called on



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

def configure_server
  yield self if server?
end

#configured?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/nsqcd.rb', line 52

def configured?
  @configured
end

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



37
38
39
40
41
42
# File 'lib/nsqcd.rb', line 37

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

#error_reportersObject

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

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

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



74
75
76
# File 'lib/nsqcd.rb', line 74

def error_reporters
  CONFIG[:error_reporters]
end

#loggerObject



48
49
50
# File 'lib/nsqcd.rb', line 48

def logger
  @logger
end

#logger=(logger) ⇒ Object



44
45
46
# File 'lib/nsqcd.rb', line 44

def logger=(logger)
  @logger = logger
end

#server=(server) ⇒ Object



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

def server=(server)
  @server = server
end

#server?Boolean

Returns:

  • (Boolean)


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

def server?
  @server
end