Class: Shinq::Configuration

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_errorBoolean

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.

Returns:

  • (Boolean)

    Whether do queue_abort() on performing failure.

See Also:



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

#daemonizeObject

Returns the value of attribute daemonize.



13
14
15
# File 'lib/shinq/configuration.rb', line 13

def daemonize
  @daemonize
end

#db_configObject

Returns the value of attribute db_config.



13
14
15
# File 'lib/shinq/configuration.rb', line 13

def db_config
  @db_config
end

#default_dbObject

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_timeoutObject

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

#lifecycleObject

Returns the value of attribute lifecycle.



13
14
15
# File 'lib/shinq/configuration.rb', line 13

def lifecycle
  @lifecycle
end

#processObject

Returns the value of attribute process.



13
14
15
# File 'lib/shinq/configuration.rb', line 13

def process
  @process
end

#queue_dbObject

Returns the value of attribute queue_db.



13
14
15
# File 'lib/shinq/configuration.rb', line 13

def queue_db
  @queue_db
end

#queue_timeoutObject

Returns the value of attribute queue_timeout.



13
14
15
# File 'lib/shinq/configuration.rb', line 13

def queue_timeout
  @queue_timeout
end

#requireObject

Returns the value of attribute require.



13
14
15
# File 'lib/shinq/configuration.rb', line 13

def require
  @require
end

#sleep_sec_on_errorObject

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

#statisticsObject

Returns the value of attribute statistics.



13
14
15
# File 'lib/shinq/configuration.rb', line 13

def statistics
  @statistics
end

#worker_nameObject

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

Returns:

  • (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_configObject

Raises:



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_classObject



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