Class: Wurk::Middleware::InterruptHandler

Inherits:
Object
  • Object
show all
Includes:
ServerMiddleware
Defined in:
lib/wurk/middleware/interrupt_handler.rb

Overview

Server middleware. Catches Wurk::Job::Interrupted raised by an IterableJob mid-iteration (or any cooperatively-cancelled job), re-pushes the job to the tail of its queue so it resumes from the persisted cursor, and raises Wurk::JobRetry::Skip so the retry layer treats this as a clean exit rather than an error.

The re-push uses RPUSH (tail of queue) so the same job is the next one to be fetched: the fetcher's LMOVE pops from the RIGHT (tail), so this job is fetched ahead of fresh LPUSH'd enqueues. The job JSON is unchanged: cursor state lives in the it-<jid> HASH (see IterableJob persistence), not in the payload. An encrypt: true job is re-sealed before the push — Encryption::ServerMiddleware restores the envelope on unwind, but a chain where it sits outside this handler would otherwise hand us decrypted args (ent §4.3).

Auto-registered at the top of the server chain when this file is required. Top-of-chain is important: a downstream middleware must not swallow the Interrupted before we see it.

Spec: docs/target/sidekiq-free.md §10.3.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#config ⇒ Object Originally defined in module ServerMiddleware

Returns the value of attribute config.

Class Method Details

.shared_instance? ⇒ Boolean

One instance per chain entry, shared by every job (Middleware::Chain::Entry): #call and its helpers keep their state in locals and write no ivar.

Returns:

  • (Boolean)


34
# File 'lib/wurk/middleware/interrupt_handler.rb', line 34

def self.shared_instance? = true

Instance Method Details

#call(_job_instance, job, queue) ⇒ Object



36
37
38
39
40
41
# File 'lib/wurk/middleware/interrupt_handler.rb', line 36

def call(_job_instance, job, queue)
  yield
rescue Wurk::Job::Interrupted
  repush(job, queue)
  raise Wurk::JobRetry::Skip
end

#logger ⇒ Object Originally defined in module ServerMiddleware

#redis(idempotent: false) ⇒ Object Originally defined in module ServerMiddleware

#redis_pool ⇒ Object Originally defined in module ServerMiddleware