lib/sidekiq/debounce.rb in sidekiq-debounce-1.0.2 vs lib/sidekiq/debounce.rb in sidekiq-debounce-1.1.0

- old
+ new

@@ -1,26 +1,32 @@ require 'sidekiq/debounce/version' require 'sidekiq/api' module Sidekiq class Debounce - def call(worker, msg, _queue, redis_pool) + def call(worker, msg, _queue, redis_pool = nil) @worker = worker.is_a?(String) ? worker.constantize : worker @msg = msg return yield unless debounce? - redis_pool.with do |conn| + block = Proc.new do |conn| # Get JID of the already-scheduled job, if there is one scheduled_jid = conn.get(debounce_key) # Reschedule the old job to when this new job is scheduled for # Or yield if there isn't one scheduled yet jid = scheduled_jid ? reschedule(scheduled_jid, @msg['at']) : yield store_expiry(conn, jid, @msg['at']) return false if scheduled_jid jid + end + + if redis_pool + redis_pool.with(&block) + else + Sidekiq.redis(&block) end end private