Class: Wurk::Batch::DeathHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/wurk/batch/death_handler.rb

Overview

Registered as a config death_handler. Fires for every job that exhausts retries or carries ‘dead: false` and discards. If the job carries a `bid`, we BATCH_ACK_COMPLETE → record the death → fire `:death` callback exactly once per batch (first death only).

Spec: docs/target/sidekiq-pro.md §2.4 (‘:death`).

Class Method Summary collapse

Class Method Details

.call(job, _exception) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/wurk/batch/death_handler.rb', line 15

def self.call(job, _exception)
  bid = job['bid']
  return unless bid

  result = Wurk.redis do |conn|
    Wurk::Lua::Loader.eval_cached(
      conn,
      :batch_ack_complete,
      keys: ["b-#{bid}", "b-#{bid}-jids", "b-#{bid}-died", "b-#{bid}-failed"],
      argv: [job['jid']]
    )
  end
  live, _died, first_death = Array(result).map(&:to_i)

  Wurk::Batch::Callbacks.fire_death(bid) if first_death == 1
  return unless live.zero?

  Wurk::Batch::Callbacks.fire_complete(bid)
  Wurk::Batch::Callbacks.propagate_to_parent(bid)
end