Class: Sidetiq::Handler

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::ExceptionHandler, Logging
Defined in:
lib/sidetiq/handler.rb

Direct Known Subclasses

Actor::Handler

Instance Method Summary collapse

Instance Method Details

#dispatch(worker, tick) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/sidetiq/handler.rb', line 8

def dispatch(worker, tick)
  schedule = worker.schedule

  return unless schedule.schedule_next?(tick)

  Lock::Redis.new(worker).synchronize do |redis|
    if schedule.backfill? && (last = worker.last_scheduled_occurrence) > 0
      last = Sidetiq.config.utc ? Time.at(last).utc : Time.at(last)
      schedule.occurrences_between(last + 1, tick).each do |past_t|
        enqueue(worker, past_t, redis)
      end
    end

    enqueue(worker, schedule.next_occurrence(tick), redis)
  end
rescue StandardError => e
  handle_exception(e, context: "Sidetiq::Handler#dispatch")
  raise e
end