Class: Qs::Daemon::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/qs/daemon.rb

Constant Summary collapse

DEFAULT_NUM_WORKERS =
4.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/qs/daemon.rb', line 284

def initialize
  @name             = nil
  @pid_file         = nil
  @shutdown_timeout = nil
  @worker_class     = DefaultWorker
  @worker_params    = nil
  @num_workers      = DEFAULT_NUM_WORKERS
  @init_procs       = []
  @error_procs      = []
  @logger           = Qs::NullLogger.new
  @queues           = []

  @verbose_logging = true

  @valid = nil
end

Instance Attribute Details

#error_procsObject

Returns the value of attribute error_procs.



281
282
283
# File 'lib/qs/daemon.rb', line 281

def error_procs
  @error_procs
end

#init_procsObject

Returns the value of attribute init_procs.



281
282
283
# File 'lib/qs/daemon.rb', line 281

def init_procs
  @init_procs
end

#loggerObject

Returns the value of attribute logger.



281
282
283
# File 'lib/qs/daemon.rb', line 281

def logger
  @logger
end

#nameObject

Returns the value of attribute name.



279
280
281
# File 'lib/qs/daemon.rb', line 279

def name
  @name
end

#num_workersObject

Returns the value of attribute num_workers.



280
281
282
# File 'lib/qs/daemon.rb', line 280

def num_workers
  @num_workers
end

#pid_fileObject

Returns the value of attribute pid_file.



279
280
281
# File 'lib/qs/daemon.rb', line 279

def pid_file
  @pid_file
end

#queuesObject

Returns the value of attribute queues.



281
282
283
# File 'lib/qs/daemon.rb', line 281

def queues
  @queues
end

#shutdown_timeoutObject

Returns the value of attribute shutdown_timeout.



279
280
281
# File 'lib/qs/daemon.rb', line 279

def shutdown_timeout
  @shutdown_timeout
end

#verbose_loggingObject

Returns the value of attribute verbose_logging.



282
283
284
# File 'lib/qs/daemon.rb', line 282

def verbose_logging
  @verbose_logging
end

#worker_classObject

Returns the value of attribute worker_class.



280
281
282
# File 'lib/qs/daemon.rb', line 280

def worker_class
  @worker_class
end

#worker_paramsObject

Returns the value of attribute worker_params.



280
281
282
# File 'lib/qs/daemon.rb', line 280

def worker_params
  @worker_params
end

Instance Method Details

#routesObject



301
302
303
# File 'lib/qs/daemon.rb', line 301

def routes
  @queues.map(&:routes).flatten
end

#valid?Boolean

Returns:

  • (Boolean)


305
306
307
# File 'lib/qs/daemon.rb', line 305

def valid?
  !!@valid
end

#validate!Object

for the config to be considered “valid”, a few things need to happen. The key here is that this only needs to be done once for each config.



312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/qs/daemon.rb', line 312

def validate!
  return @valid if !@valid.nil? # only need to run this once per config

  # ensure all user and plugin configs/settings are applied
  self.init_procs.each(&:call)
  if self.queues.empty? || self.name.nil?
    raise InvalidError, "a name and at least 1 queue must be configured"
  end

  # validate the worker class
  if !self.worker_class.kind_of?(Class) || !self.worker_class.include?(Qs::Worker)
    raise InvalidError, "worker class must include `#{Qs::Worker}`"
  end

  # validate the routes
  self.routes.each(&:validate!)

  @valid = true # if it made it this far, it's valid!
end