agilord / cron

A cron-like time-based job scheduler for Dart
BSD 3-Clause "New" or "Revised" License
116 stars 23 forks source link

second based scheduling isn't reliable #49

Open bsutton opened 9 months ago

bsutton commented 9 months ago

As I understand it, the scheduler works by setting a timer to go off every second.

The problem with this is that in an async environment, a compute-heavy workload can result in the timer being delayed.

When doing a seconds-based schedule this can mean that the task may never be run as the scheduler checks that the current time = the schedule no. of seconds.

The result is that cron is unreliable for seconds based scheduling and may be unreliable for minutes based scheduling if a very heavy process is run.

Ideally, we need to guarantee that tasks are run, even if they are late.

isoos commented 9 months ago

Good points. Open for PRs :-)

bsutton commented 9 months ago

Probably not going to have time, I'm in the middle of raising PRS against shelf_letsencrypt. I'm using Cron to trigger certificate renewals.

On Sun, 10 Dec 2023, 8:52 am István Soós, @.***> wrote:

Good points. Open for PRs :-)

— Reply to this email directly, view it on GitHub https://github.com/agilord/cron/issues/49#issuecomment-1848724102, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAG32OC2I367YRY37GAUHJ3YITMSLAVCNFSM6AAAAABAOB6VG6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNBYG4ZDIMJQGI . You are receiving this because you authored the thread.Message ID: @.***>

busslina commented 4 months ago

I'm using Cron to trigger certificate renewals.

Maybe for certificate renewals it is better to schedule one by one renewal (instead of using cron based scheduling) because with cron you are not taking care of the time spent in the renewal.

EG: If a certificate ends at 19:54:36, the next could end at 19:55:12.

So, yes, you can use a Cron based solution if you schedule it with some days of margin (like 85 days instead the default 89 days).

But at the end I agree with you. This lib should ensure the execution, even if it's late.