Class: Shinq::Configuration
- Inherits:
-
Object
- Object
- Shinq::Configuration
- Defined in:
- lib/shinq/configuration.rb
Constant Summary collapse
- DEFAULT =
{ require: '.', process: 1, graceful_kill_timeout: 600, queue_timeout: 1, daemonize: false, abort_on_error: true, sleep_sec_on_error: 1, }
Instance Attribute Summary collapse
-
#abort_on_error ⇒ Boolean
Defaults to
true
, which means that worker do queue_end() AFTER it proceeds a job. -
#daemonize ⇒ Object
Returns the value of attribute daemonize.
-
#db_config ⇒ Object
Returns the value of attribute db_config.
-
#default_db ⇒ Object
Returns the value of attribute default_db.
-
#graceful_kill_timeout ⇒ Object
Returns the value of attribute graceful_kill_timeout.
-
#lifecycle ⇒ Object
Returns the value of attribute lifecycle.
-
#process ⇒ Object
Returns the value of attribute process.
-
#queue_db ⇒ Object
Returns the value of attribute queue_db.
-
#queue_timeout ⇒ Object
Returns the value of attribute queue_timeout.
-
#require ⇒ Object
Returns the value of attribute require.
-
#sleep_sec_on_error ⇒ Object
Returns the value of attribute sleep_sec_on_error.
-
#statistics ⇒ Object
Returns the value of attribute statistics.
-
#worker_name ⇒ Object
Returns the value of attribute worker_name.
Instance Method Summary collapse
- #db_defined?(db_name) ⇒ Boolean
- #default_db_config ⇒ Object
-
#initialize(opts) ⇒ Configuration
constructor
A new instance of Configuration.
- #worker_class ⇒ Object
Constructor Details
#initialize(opts) ⇒ Configuration
Returns a new instance of Configuration.
25 26 27 28 29 30 |
# File 'lib/shinq/configuration.rb', line 25 def initialize(opts) %i(require worker_name db_config queue_db default_db process queue_timeout daemonize statistics lifecycle abort_on_error sleep_sec_on_error).each do |k| value = opts.key?(k) ? opts[k] : DEFAULT[k] send(:"#{k}=", value) end end |
Instance Attribute Details
#abort_on_error ⇒ Boolean
Defaults to true
, which means that worker do queue_end() AFTER it proceeds a job. If it is false
, worker do queue_end() BEFORE it proceeds a job. You may need to set it false
for jobs which take very long time to proceed. You may also need to handle performing error manually then.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/shinq/configuration.rb', line 12 class Configuration attr_accessor :require, :worker_name, :db_config, :queue_db, :default_db, :process, :graceful_kill_timeout, :queue_timeout, :daemonize, :statistics, :lifecycle, :abort_on_error, :sleep_sec_on_error DEFAULT = { require: '.', process: 1, graceful_kill_timeout: 600, queue_timeout: 1, daemonize: false, abort_on_error: true, sleep_sec_on_error: 1, } def initialize(opts) %i(require worker_name db_config queue_db default_db process queue_timeout daemonize statistics lifecycle abort_on_error sleep_sec_on_error).each do |k| value = opts.key?(k) ? opts[k] : DEFAULT[k] send(:"#{k}=", value) end end def worker_class worker_class = worker_name.camelize.safe_constantize unless worker_class raise ConfigurationError, "worker class #{worker_name.camelize} corresponding to #{worker_name} does not exist" end worker_class end def default_db_config raise ConfigurationError if !(default_db && db_defined?(default_db)) db_config[default_db] end def db_defined?(db_name) !!(db_config && db_config[db_name]) end end |
#daemonize ⇒ Object
Returns the value of attribute daemonize.
13 14 15 |
# File 'lib/shinq/configuration.rb', line 13 def daemonize @daemonize end |
#db_config ⇒ Object
Returns the value of attribute db_config.
13 14 15 |
# File 'lib/shinq/configuration.rb', line 13 def db_config @db_config end |
#default_db ⇒ Object
Returns the value of attribute default_db.
13 14 15 |
# File 'lib/shinq/configuration.rb', line 13 def default_db @default_db end |
#graceful_kill_timeout ⇒ Object
Returns the value of attribute graceful_kill_timeout.
13 14 15 |
# File 'lib/shinq/configuration.rb', line 13 def graceful_kill_timeout @graceful_kill_timeout end |
#lifecycle ⇒ Object
Returns the value of attribute lifecycle.
13 14 15 |
# File 'lib/shinq/configuration.rb', line 13 def lifecycle @lifecycle end |
#process ⇒ Object
Returns the value of attribute process.
13 14 15 |
# File 'lib/shinq/configuration.rb', line 13 def process @process end |
#queue_db ⇒ Object
Returns the value of attribute queue_db.
13 14 15 |
# File 'lib/shinq/configuration.rb', line 13 def queue_db @queue_db end |
#queue_timeout ⇒ Object
Returns the value of attribute queue_timeout.
13 14 15 |
# File 'lib/shinq/configuration.rb', line 13 def queue_timeout @queue_timeout end |
#require ⇒ Object
Returns the value of attribute require.
13 14 15 |
# File 'lib/shinq/configuration.rb', line 13 def require @require end |
#sleep_sec_on_error ⇒ Object
Returns the value of attribute sleep_sec_on_error.
13 14 15 |
# File 'lib/shinq/configuration.rb', line 13 def sleep_sec_on_error @sleep_sec_on_error end |
#statistics ⇒ Object
Returns the value of attribute statistics.
13 14 15 |
# File 'lib/shinq/configuration.rb', line 13 def statistics @statistics end |
#worker_name ⇒ Object
Returns the value of attribute worker_name.
13 14 15 |
# File 'lib/shinq/configuration.rb', line 13 def worker_name @worker_name end |
Instance Method Details
#db_defined?(db_name) ⇒ Boolean
45 46 47 |
# File 'lib/shinq/configuration.rb', line 45 def db_defined?(db_name) !!(db_config && db_config[db_name]) end |
#default_db_config ⇒ Object
40 41 42 43 |
# File 'lib/shinq/configuration.rb', line 40 def default_db_config raise ConfigurationError if !(default_db && db_defined?(default_db)) db_config[default_db] end |
#worker_class ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/shinq/configuration.rb', line 32 def worker_class worker_class = worker_name.camelize.safe_constantize unless worker_class raise ConfigurationError, "worker class #{worker_name.camelize} corresponding to #{worker_name} does not exist" end worker_class end |