jmettraux/rufus-scheduler

Cronline error with frequency

Closed this issue · 5 comments

Hi! I was just using rufus-scheduler on version 3.4.2, through the sidekiq-cron gem. I was trying to schedule a job every 15 minutes, so I used the following notation:
0/15 * * * *

But my job wasn't being scheduled but once per hour.

I then tried changing it to 0,15,30,45 * * * *, and everything started working.

I took my chance to review it and I've found the following behaviour:

[8] pry(main)> Rufus::Scheduler.parse("0/15 * * * * Etc/GMT").brute_frequency
=> 3600.0
[9] pry(main)> Rufus::Scheduler.parse("0,15,30,45 * * * * Etc/GMT").brute_frequency
=> 900.0
[10] pry(main)> Rufus::Scheduler.parse("0/15 * * * * Etc/GMT").next_time
=> #<EtOrbi::EoTime:0x00007f869d8182d0 @seconds=1548450000.0, @time=2019-01-25 21:00:00 UTC, @zone=#<TZInfo::DataTimezone: Etc/GMT>>
[11] pry(main)> Rufus::Scheduler.parse("0,15,30,45 * * * * Etc/GMT").next_time
=> #<EtOrbi::EoTime:0x00007f869d55b9c0 @seconds=1548447300.0, @time=2019-01-25 20:15:00 UTC, @zone=#<TZInfo::DataTimezone: Etc/GMT>>
[12] pry(main)> Rufus::Scheduler.parse("0/15 * * * * Etc/GMT").to_array
=> [[0], [0], nil, nil, nil, nil, nil, "Etc/GMT"]
[13] pry(main)> Rufus::Scheduler.parse("0,15,30,45 * * * * Etc/GMT").to_array
=> [[0], [0, 15, 30, 45], nil, nil, nil, nil, nil, "Etc/GMT"]
[14] pry(main)> time = Time.local(2019,1,25,17,15,0)
=> 2019-01-25 17:15:00 -0300
[15] pry(main)> Rufus::Scheduler.parse("0,15,30,45 * * * * Etc/GMT").matches?(time)
=> true
[16] pry(main)> Rufus::Scheduler.parse("0/15 * * * * Etc/GMT").matches?(time)
=> false
[17] pry(main)> time = Time.local(2019,1,25,17,0,0)
=> 2019-01-25 17:00:00 -0300
[18] pry(main)> Rufus::Scheduler.parse("0,15,30,45 * * * * Etc/GMT").matches?(time)
=> true
[19] pry(main)> Rufus::Scheduler.parse("0/15 * * * * Etc/GMT").matches?(time)
=> true

As you can see, the / notation is not working in this case. I've figured out the other notation to overcome this, but just for you to know.

Here's the same for version 3.5.2:

[1] pry(main)> Rufus::Scheduler.parse("0/15 * * * * Etc/GMT").brute_frequency
=> #<Fugit::Cron::Frequency:0x00007f9985bd0080 @delta_max=3600, @delta_min=3600, @occurrences=8760, @span=31536000.0, @span_years=1.0, @yearly_occurrences=8760.0>
[2] pry(main)> Rufus::Scheduler.parse("0,15,30,45 * * * * Etc/GMT").brute_frequency
=> #<Fugit::Cron::Frequency:0x00007f998915f8e0 @delta_max=900, @delta_min=900, @occurrences=35040, @span=31536000.0, @span_years=1.0, @yearly_occurrences=35040.0>
[3] pry(main)> Rufus::Scheduler.parse("0/15 * * * * Etc/GMT").next_time
=> #<EtOrbi::EoTime:0x00007f99890e6ff8 @seconds=1548450000.0, @time=nil, @zone=#<TZInfo::TimezoneProxy: America/Argentina/Buenos_Aires>>
[4] pry(main)> Rufus::Scheduler.parse("0,15,30,45 * * * * Etc/GMT").next_time
=> #<EtOrbi::EoTime:0x00007f998902a678 @seconds=1548449100.0, @time=nil, @zone=#<TZInfo::TimezoneProxy: America/Argentina/Buenos_Aires>>
[6] pry(main)> time = Time.local(2019,1,25,17,15,0)
=> 2019-01-25 17:15:00 -0300
[8] pry(main)> Rufus::Scheduler.parse("0,15,30,45 * * * * Etc/GMT").match?(time)
=> true
[9] pry(main)> Rufus::Scheduler.parse("0/15 * * * * Etc/GMT").match?(time)
=> false
[10] pry(main)> time = Time.local(2019,1,25,17,0,0)
=> 2019-01-25 17:00:00 -0300
[11] pry(main)> Rufus::Scheduler.parse("0,15,30,45 * * * * Etc/GMT").match?(time)
=> true
[12] pry(main)> Rufus::Scheduler.parse("0/15 * * * * Etc/GMT").match?(time)
=> true

I've noticed that this isn't working either, and that you have changed from Rufus::Scheduler::CronLine to Fugit::CronLine, so seems like it's a bug on them, right?

Hello,

0/15 * * * * means, for fugit and rufus-scheduler, "in the range from the minute 0 to the minute 0, with a step of 15 minutes", and only the minute 0 fits that.

What you are trying to achieve is */15 * * * * or 0-59/15 * * * * which means "in the range from minute 0 to 59, with a step of 15 minutes".

Where did you get that "0/15 * * * *" from? What piece of documentation? It's been 10 years and you're the first one to complain about that.

Also please upgrade to the latest fugit, it fixes an issue with cron and timezones.

Best regards.

Hi, sorry for the misundestanding! I'm not too familiar with the cron notation, so I used this website to generate it.

As you pointed out in your first comment, it might not be standard, so maybe the generator don't take it into account.

Then again, sorry for that! I'll start using the */15 notation 🙂 and thanks for the quick answer!

You're welcome!