Class: Wurk::Unique::ClientMiddleware

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

Overview


Client middleware — SETNX lock at push time.


Drops the duplicate by returning nil from the chain (Wurk::Client treats nil as “halted”; the caller’s ‘perform_async` returns nil JID). Logs the holder JID for debuggability.

Instance Method Summary collapse

Instance Method Details

#call(_worker, job, _queue, redis_pool) ⇒ Object



148
149
150
151
152
153
154
155
# File 'lib/wurk/unique.rb', line 148

def call(_worker, job, _queue, redis_pool, &)
  return yield unless Wurk::Unique.enabled?

  ttl = effective_ttl(job)
  return yield if ttl.nil?

  acquire_or_drop(redis_pool, job, Wurk::Unique.lock_key_for(job), ttl, &)
end