Class: Wurk::Batch::ServerMiddleware

Inherits:
Object
  • Object
show all
Includes:
Middleware::ServerMiddleware
Defined in:
lib/wurk/batch/server_middleware.rb

Overview

Server middleware. Runs around perform for any job carrying a bid. On success → BATCH_ACK_SUCCESS → if pending hit zero and no deaths, enqueue :success callback jobs; if live jids hit zero, enqueue :complete callback jobs.

On a job raising (and thus heading to retry), records a transient failure → BATCH_ACK_FAILED → the jid joins b-<bid>-failed and failures reflects the count of currently-failing jobs. A later successful retry clears it; a terminal death moves it to b-<bid>-died. Clean handled exits (JobRetry::Skip from expiry/interrupt, cooperative IterableJob interruption) are re-raised without counting as failures.

Invalidated batches short-circuit: the job is skipped without raising — counts as a "success" for batch purposes per spec §12.

Death handling lives in Wurk::Batch::DeathHandler (registered as a config death_handler) because death is signalled from the retry layer, not from this middleware's rescue path.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject Originally defined in module Middleware::ServerMiddleware

Returns the value of attribute config.

Instance Method Details

#call(_worker, job, _queue) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/wurk/batch/server_middleware.rb', line 32

def call(_worker, job, _queue)
  bid = job['bid']
  return yield unless bid

  if invalidated?(bid)
    ack_success(bid, job['jid'])
    return
  end

  run_and_ack(bid, job['jid']) { yield }
end

#loggerObject Originally defined in module Middleware::ServerMiddleware

#redisObject Originally defined in module Middleware::ServerMiddleware

#redis_poolObject Originally defined in module Middleware::ServerMiddleware