cron icon indicating copy to clipboard operation
cron copied to clipboard

Job scheduled for between 5 years and 100000 hours will not be run

Open andrewchambers opened this issue 3 years ago • 7 comments

According to this line, no next time will be returned if the next action is outside 5 years: https://github.com/robfig/cron/blob/e843a09e5b2db454d77aad25b1660173445fb2fc/spec.go#L87

In the main cron loop the time, if no next time is found, it will wait 100000 hours:

https://github.com/robfig/cron/blob/e843a09e5b2db454d77aad25b1660173445fb2fc/cron.go#L252

This means in the time window between 5 years and 100000 hours you can skip a job by accident.

I may be mistaken, but i thought it was a fun bug.

andrewchambers avatar Jun 03 '21 05:06 andrewchambers

Yes, because of the way it calculates the next job's trigger time (iteration), it has to pick some threshold beyond which it gives up. 5 years is an amount of time beyond which it seemed implausible to have any use case for scheduling a job farther out. 100k hours is more like 11 years, which is outside that realm. I'd be happy to review a fix that removes that limitation, but it seems low priority and wouldn't be worth a great complication IMO.

robfig avatar Oct 17 '21 14:10 robfig

@robfig I guess the fix is to just bring those two windows into sync.

andrewchambers avatar Oct 18 '21 00:10 andrewchambers

dude if you're running stuff so insanely long you need to run

//pull this out of a database or whatever
if 1793907730 < time.Now().Unix() {
    //do your tasks
}

because this will traverse reboots, server changes, computer changes, database updates, program restarts, etc... and yours will reset it's timer everytime anything happens.

G2G2G2G avatar Nov 05 '21 19:11 G2G2G2G

@G2G2G2G obviously - its just a low impact bug. Not every server is rebooted every 5 years so I just thought it was funny if anyone actually has such a crazy cron job.

andrewchambers avatar Nov 05 '21 22:11 andrewchambers

That's a wait timer not a cron job..

G2G2G2G avatar Nov 11 '21 23:11 G2G2G2G

Please reread and understand the original issue before commenting again I am unsubscribing from this issue as I have no intention of fixing it - just reporting it.

andrewchambers avatar Nov 11 '21 23:11 andrewchambers

https://crontab.guru/ demonstrate a cron job that runs in 5 years

G2G2G2G avatar Nov 12 '21 00:11 G2G2G2G