jmettraux/rufus-scheduler

When I add a cron job with a time in the past, I get a scheduled job in the future

Closed this issue · 1 comments

I added numerous cron jobs, with the cron syntax, and some of them has already passed. For example:
"24 0 4 7 1" which translates to 24 minutes 0 hours 4th day of 7th month what is monday.

I used the sytax:

scheduler.cron("24 0 4 7 1") do 
  system(my_command)
end

After that I get a scheduled job:

scheduler.jobs[0].next_time
returns
1685831040.0
Which is in 2023

Time.at(scheduler.jobs[0].next_time.seconds)
returns
2023-06-04 00:24:00 +0200

I sould use #at instead of #cron, but #at can't parse cron timing syntax.

Good day,

When I add a cron job with a time in the past, I get a scheduled job in the future.

scheduler.cron("24 0 4 7 1")

What does say in this that this cron job points at a time in the past?

I am sorry, I am a mediocre programmer. I do not know how to trigger jobs in the past.

Maybe first_time: could help you:

require 'rufus-scheduler'

scheduler = Rufus::Scheduler.new

scheduler.cron('24 0 4 7 1', first_time: Time.now + 7) do |job|
  p [ Time.now, :hello ]
  p [ job.next_time.to_s, job.next_time.wday ]
end

scheduler.join

I sould use #at instead of #cron, but #at can't parse cron timing syntax.

Maybe you want to use times:.

scheduler.cron("24 0 4 7 1", times: 1) do 
  # ...
end

which will trigger (in the future) only once.

I am closing the issue, but if anything is unclear, please ask. Kind regards.