Class: Sidekiq::RequeueMissingClass::Middleware
- Inherits:
-
Object
- Object
- Sidekiq::RequeueMissingClass::Middleware
- Defined in:
- lib/sidekiq/requeue_missing_class/middleware.rb
Overview
Server middleware that re-queues a job when the class meant to run it is not defined in the current worker process.
During a rolling deploy that introduces a new job class, a freshly started pod (or a scheduler) can enqueue a job for a class that the still-running OLD workers do not have yet. An old worker that pops it would otherwise blow up (ActiveJob::UnknownJobClassError / NameError). Instead we push the job back with a short delay so an updated worker — which has the class — picks it up once the rollout finishes.
Constant Summary collapse
- ACTIVE_JOB_WRAPPERS =
ActiveJob wraps the real job; the wrapper class is always present, so we have to look one level deeper at the wrapped job_class.
[ "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper", "Sidekiq::ActiveJob::Wrapper" ].freeze
- COUNTER_KEY =
"requeue_missing_class_count"
Instance Method Summary collapse
Instance Method Details
#call(_worker, job, queue) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/sidekiq/requeue_missing_class/middleware.rb', line 24 def call(_worker, job, queue) target = target_class_name(job) return yield if target.nil? || loadable?(target) attempts = job.fetch(COUNTER_KEY, 0) return yield if attempts >= config.max_requeues requeue(job, queue, target, attempts) end |