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 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



263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/wurk/unique.rb', line 263

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

#loggerObject Originally defined in module Middleware::ServerMiddleware

#redisObject Originally defined in module Middleware::ServerMiddleware

#redis_poolObject Originally defined in module Middleware::ServerMiddleware