Class: Qs::Daemon::Config
- Inherits:
-
Object
- Object
- Qs::Daemon::Config
- Defined in:
- lib/qs/daemon.rb
Constant Summary collapse
- DEFAULT_NUM_WORKERS =
4.freeze
Instance Attribute Summary collapse
-
#error_procs ⇒ Object
Returns the value of attribute error_procs.
-
#init_procs ⇒ Object
Returns the value of attribute init_procs.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#name ⇒ Object
Returns the value of attribute name.
-
#num_workers ⇒ Object
Returns the value of attribute num_workers.
-
#pid_file ⇒ Object
Returns the value of attribute pid_file.
-
#queues ⇒ Object
Returns the value of attribute queues.
-
#shutdown_timeout ⇒ Object
Returns the value of attribute shutdown_timeout.
-
#verbose_logging ⇒ Object
Returns the value of attribute verbose_logging.
-
#worker_class ⇒ Object
Returns the value of attribute worker_class.
-
#worker_params ⇒ Object
Returns the value of attribute worker_params.
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #routes ⇒ Object
- #valid? ⇒ Boolean
-
#validate! ⇒ Object
for the config to be considered “valid”, a few things need to happen.
Constructor Details
#initialize ⇒ Config
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_procs ⇒ Object
Returns the value of attribute error_procs.
281 282 283 |
# File 'lib/qs/daemon.rb', line 281 def error_procs @error_procs end |
#init_procs ⇒ Object
Returns the value of attribute init_procs.
281 282 283 |
# File 'lib/qs/daemon.rb', line 281 def init_procs @init_procs end |
#logger ⇒ Object
Returns the value of attribute logger.
281 282 283 |
# File 'lib/qs/daemon.rb', line 281 def logger @logger end |
#name ⇒ Object
Returns the value of attribute name.
279 280 281 |
# File 'lib/qs/daemon.rb', line 279 def name @name end |
#num_workers ⇒ Object
Returns the value of attribute num_workers.
280 281 282 |
# File 'lib/qs/daemon.rb', line 280 def num_workers @num_workers end |
#pid_file ⇒ Object
Returns the value of attribute pid_file.
279 280 281 |
# File 'lib/qs/daemon.rb', line 279 def pid_file @pid_file end |
#queues ⇒ Object
Returns the value of attribute queues.
281 282 283 |
# File 'lib/qs/daemon.rb', line 281 def queues @queues end |
#shutdown_timeout ⇒ Object
Returns the value of attribute shutdown_timeout.
279 280 281 |
# File 'lib/qs/daemon.rb', line 279 def shutdown_timeout @shutdown_timeout end |
#verbose_logging ⇒ Object
Returns the value of attribute verbose_logging.
282 283 284 |
# File 'lib/qs/daemon.rb', line 282 def verbose_logging @verbose_logging end |
#worker_class ⇒ Object
Returns the value of attribute worker_class.
280 281 282 |
# File 'lib/qs/daemon.rb', line 280 def worker_class @worker_class end |
#worker_params ⇒ Object
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
#routes ⇒ Object
301 302 303 |
# File 'lib/qs/daemon.rb', line 301 def routes @queues.map(&:routes).flatten end |
#valid? ⇒ 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 |