Module: Sidekiq::Batch::Jobs

Defined in:
lib/sidekiq/batch/jobs.rb,
lib/sidekiq/batch/jobs/engine.rb,
lib/sidekiq/batch/jobs/version.rb,
lib/sidekiq/batch/jobs/enum_compat.rb,
lib/sidekiq/batch/jobs/configuration.rb,
lib/sidekiq/batch/jobs/failure_policy.rb,
lib/generators/sidekiq/batch/jobs/install/install_generator.rb

Defined Under Namespace

Modules: EnumCompat, Generators Classes: Configuration, Engine, Error, FailurePolicy

Constant Summary collapse

DEATH_HANDLER =

Reconciles jobs that died without re-entering the server middleware (SIGKILL, OOM, pod eviction). A constant, not an inline lambda: the body names SidekiqBatch only when a job dies, so registering never autoloads app code, and one stable identity lets us register it exactly once.

->(job, error) { ::SidekiqBatch::Middleware.handle_death(job, error) }
VERSION =
"0.2.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configObject



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

def self.config
  @config ||= Configuration.new
end

Class Method Details

.auto_installObject



42
43
44
# File 'lib/sidekiq/batch/jobs.rb', line 42

def self.auto_install
  config.auto_install
end

.base_classObject

Convenience readers for the two settings read where the extra .config hop is noise: a model's class body and the engine's to_prepare hook.



38
39
40
# File 'lib/sidekiq/batch/jobs.rb', line 38

def self.base_class
  config.base_class
end

.configure {|config| ... } ⇒ Object

Host entry point. See Configuration for the full set of knobs.

Yields:



30
31
32
33
34
# File 'lib/sidekiq/batch/jobs.rb', line 30

def self.configure
  yield config

  config
end

.install!Object

Safe to call repeatedly. The engine calls it from config.to_prepare, which runs at boot and again after every code reload.

Deliberately not Sidekiq.configure_client / configure_server: configure_server appends its block to Sidekiq's @config_blocks, which configure_embed later replays, so calling it once per reload would grow that list without bound.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/sidekiq/batch/jobs.rb', line 53

def self.install!
  sidekiq_config = ::Sidekiq.default_configuration

  register_death_handler(sidekiq_config)

  # Outermost on the client chain, so dedupe/suppression middleware added
  # later with `chain.add` has the final say on whether a push happens: we
  # enroll only jobs the rest of the chain agrees to push. A server process
  # has its own client chain, so this covers both.
  sidekiq_config.client_middleware { |chain| rebind(chain, ::SidekiqBatch::ClientMiddleware, :prepend) }

  return unless ::Sidekiq.server?

  # `add`, not `prepend`, so this runs LAST in the server chain, outside
  # Sidekiq's retry middleware, and sees each attempt's final disposition.
  sidekiq_config.server_middleware { |chain| rebind(chain, ::SidekiqBatch::Middleware, :add) }
end