Module: SidekiqSchedulable::Schedule

Defined in:
lib/sidekiq_schedulable/schedule.rb

Class Method Summary collapse

Class Method Details

.enqueue(schedule, last_run = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/sidekiq_schedulable/schedule.rb', line 5

def self.enqueue(schedule, last_run = nil)
  return if schedule[:crons].empty?

  worker = schedule[:worker]
  schedule[:crons].each do |cron|
    time = next_time(cron)
    if schedule[:options][:last_run]
      last_time = last_run || last_time(cron)
      worker.perform_at(time, last_time.to_f)
    else
      worker.perform_at(time)
    end
  end
end

.last_time(schedule) ⇒ Object



24
25
26
# File 'lib/sidekiq_schedulable/schedule.rb', line 24

def self.last_time(schedule)
  CronParser.new(schedule).last(Time.now)
end

.next_time(schedule) ⇒ Object



20
21
22
# File 'lib/sidekiq_schedulable/schedule.rb', line 20

def self.next_time(schedule)
  CronParser.new(schedule).next(Time.now)
end