Class: Sidekiq::Debounce

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/debounce.rb,
lib/sidekiq/debounce/version.rb

Constant Summary collapse

VERSION =
'1.0.0'

Instance Method Summary collapse

Instance Method Details

#call(worker, msg, _queue, redis_pool) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/sidekiq/debounce.rb', line 6

def call(worker, msg, _queue, redis_pool)
  @worker = worker
  @msg = msg

  return yield unless debounce?

  redis_pool.with 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
end