Class: SidekiqBatch::Middleware
- Inherits:
-
Object
- Object
- SidekiqBatch::Middleware
- Defined in:
- app/models/sidekiq_batch/middleware.rb
Constant Summary collapse
- DEFAULT_MAX_RETRIES =
25
Class Method Summary collapse
- .check_completion(batch_id) ⇒ Object
-
.handle_death(job, error) ⇒ Object
Also used by the Sidekiq death handler to reconcile jobs that died without re-entering middleware (SIGKILL, OOM, pod eviction, etc.).
Instance Method Summary collapse
Class Method Details
.check_completion(batch_id) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'app/models/sidekiq_batch/middleware.rb', line 33 def self.check_completion(batch_id) ::SidekiqBatch.attempt_completion!(batch_id) rescue StandardError => e ::Sidekiq::Batch::Jobs.config.alert( "SidekiqBatch ##{batch_id}: completion check failed after a job reached a " \ "terminal state (#{e.class}: #{e.}). The reaper will pick it up." ) nil end |
.handle_death(job, error) ⇒ Object
Also used by the Sidekiq death handler to reconcile jobs that died without re-entering middleware (SIGKILL, OOM, pod eviction, etc.).
24 25 26 27 28 29 30 31 |
# File 'app/models/sidekiq_batch/middleware.rb', line 24 def self.handle_death(job, error) batch_id = job[PAYLOAD_BATCH_ID_KEY] return unless batch_id return unless ::SidekiqBatchJob.fail!(job["jid"], error) check_completion(batch_id) end |
Instance Method Details
#call(worker, job, _queue) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/models/sidekiq_batch/middleware.rb', line 7 def call(worker, job, _queue) batch_id = job[PAYLOAD_BATCH_ID_KEY] return yield unless batch_id begin yield rescue StandardError => e record_failure(worker, job, batch_id, e) raise end handle_success(job, batch_id) end |