Class: Sidekiq::Batch::Jobs::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/batch/jobs/configuration.rb

Overview

Everything a host can tune, through Sidekiq::Batch::Jobs.configure. An initializer is the right place: it runs before any model is autoloaded, which base_class_name requires.

Constant Summary collapse

DEFAULT_BASE_CLASS_NAME =
"ActiveRecord::Base"
DEFAULT_STUCK_AFTER =

2 hours

2 * 60 * 60
DEFAULT_RETENTION =

30 days

30 * 24 * 60 * 60
DEFAULT_ERROR_MESSAGE_MAX =
4_000
DEFAULT_MAINTENANCE_QUEUE =
"default"
DEFAULT_FAILURE_POLICY =
:any_failure
DEFAULT_ON_ALERT =

Warn rather than stay silent: the reaper only speaks up after it has marked someone's jobs failed or re-fired a callback. Never routine.

->(message) { ::Sidekiq.logger.warn("[sidekiq-batch-jobs] #{message}") }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



31
32
33
34
35
36
37
38
39
40
# File 'lib/sidekiq/batch/jobs/configuration.rb', line 31

def initialize
  @auto_install      = true
  @base_class_name   = DEFAULT_BASE_CLASS_NAME
  @stuck_after       = DEFAULT_STUCK_AFTER
  @retention         = DEFAULT_RETENTION
  @error_message_max = DEFAULT_ERROR_MESSAGE_MAX
  @maintenance_queue = DEFAULT_MAINTENANCE_QUEUE
  @on_alert          = DEFAULT_ON_ALERT
  @failure_policy    = FailurePolicy.normalize(DEFAULT_FAILURE_POLICY)
end

Instance Attribute Details

#auto_installObject

Returns the value of attribute auto_install.



21
22
23
# File 'lib/sidekiq/batch/jobs/configuration.rb', line 21

def auto_install
  @auto_install
end

#base_class_nameObject

Returns the value of attribute base_class_name.



29
30
31
# File 'lib/sidekiq/batch/jobs/configuration.rb', line 29

def base_class_name
  @base_class_name
end

#error_message_maxObject

In characters, not bytes.



24
25
26
# File 'lib/sidekiq/batch/jobs/configuration.rb', line 24

def error_message_max
  @error_message_max
end

#failure_policyObject

Returns the value of attribute failure_policy.



29
30
31
# File 'lib/sidekiq/batch/jobs/configuration.rb', line 29

def failure_policy
  @failure_policy
end

#maintenance_queueObject

Returns the value of attribute maintenance_queue.



21
22
23
# File 'lib/sidekiq/batch/jobs/configuration.rb', line 21

def maintenance_queue
  @maintenance_queue
end

#on_alertObject

Callable taking one String, or nil to silence entirely.



27
28
29
# File 'lib/sidekiq/batch/jobs/configuration.rb', line 27

def on_alert
  @on_alert
end

#retentionObject

Returns the value of attribute retention.



29
30
31
# File 'lib/sidekiq/batch/jobs/configuration.rb', line 29

def retention
  @retention
end

#stuck_afterObject

Returns the value of attribute stuck_after.



29
30
31
# File 'lib/sidekiq/batch/jobs/configuration.rb', line 29

def stuck_after
  @stuck_after
end

Instance Method Details

#alert(message) ⇒ Object

A broken alert channel must not take down the reaper run that was trying to report through it.



76
77
78
79
80
81
82
# File 'lib/sidekiq/batch/jobs/configuration.rb', line 76

def alert(message)
  on_alert&.call(message)
rescue StandardError => e
  ::Sidekiq.logger.error(
    "[sidekiq-batch-jobs] on_alert raised #{e.class}: #{e.message} — original message: #{message}"
  )
end

#base_classObject

Never memoised, so each reload of the models picks up the current object. const_get rather than constantize because this runs from a model class body, where ActiveSupport may not be loaded yet.



53
54
55
# File 'lib/sidekiq/batch/jobs/configuration.rb', line 53

def base_class
  ::Object.const_get(base_class_name)
end