jmettraux/rufus-scheduler

Get second and third next_time

filipeaugustosantos opened this issue · 3 comments

How to get the next events?
For example, I need a list of the next three executions.

Good morning,

for a start, you could do something along those lines:

require 'rufus-scheduler'

scheduler = Rufus::Scheduler.new
scheduler.cron '1 * * * *' do; end
scheduler.every '2m' do; end
scheduler.in '3m' do; end

scheduler.jobs.each do |job|
  p [ job.class, job.original, job.next_time.to_t ]
end

Closing the "issue", not the conversation.

Best regards.

Thanks for the reply, but I'm looking at how to get the next three executions of the same job.

I got that way

cron = js[0].to_s
begin
t1 = Rufus::Scheduler.parse(cron).next_time.to_s
t2 = Rufus::Scheduler.parse(cron).next_time(t1).to_s
t3 = Rufus::Scheduler.parse(cron).next_time(t2).to_s
result << t1.to_s
result << t2.to_s
result << t3.to_s
rescue
end