Class: Wurk::Unique::ServerMiddleware

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

Overview


Server middleware — release lock per ‘unique_until` strategy.


‘:start` → DEL before perform. Lock-after-this-point not held; a

duplicate can be re-enqueued while the first runs.

‘:success` → DEL only on successful return. Retries keep the lock.

Spec §3.7: a raise during perform leaves the lock so
the retry can proceed; the TTL bounds the worst case.

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



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/wurk/unique.rb', line 201

def call(_worker, job, _queue)
  return yield unless Wurk::Unique.enabled? && Wurk::Unique.coerce_ttl(job['unique_for'])

  mode = unique_until(job)
  key = Wurk::Unique.lock_key_for(job)

  if mode == :start
    release(key, job['jid'])
    yield
  else
    result = yield
    release(key, job['jid'])
    result
  end
end