Class: Wurk::Limiter::ServerMiddleware

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

Overview

Catches OverLimit (and any class registered in ‘Limiter.config.errors`), bumps `job`, and decides what to do next:

* reschedule disabled (`reschedule: 0`) → re-raise so the normal
  retry/dead pipeline handles it (spec §1.2/§1.4 behaviour).
* still under the cap → reschedule onto the same queue at
  `Time.now + backoff` via `Client.push`.
* cap reached (`overrated >= reschedule`, default 20) → **poison
  brake** (#16): a job that's still rate-limited after N reschedules
  is saturating the limiter, so instead of dumping it into another
  25× retry loop we route it straight to the dead set tagged
  `rate_limited`, bumping `jobs.rate_limited` and firing death
  handlers. Bounded: termination at exactly `reschedule` attempts.

Constant Summary collapse

DEAD_REASON =
'rate_limited'

Instance Attribute Summary

Attributes included from Middleware::ServerMiddleware

#config

Instance Method Summary collapse

Methods included from Middleware::ServerMiddleware

#logger, #redis, #redis_pool

Instance Method Details

#call(_worker, job, _queue) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/wurk/limiter/server_middleware.rb', line 23

def call(_worker, job, _queue)
  yield
rescue StandardError => e
  raise unless over_limit?(e)

  handle_over_limit(job, e)
end