rq / rq-scheduler

A lightweight library that adds job scheduling capabilities to RQ (Redis Queue)
MIT License
1.45k stars 230 forks source link

Duplicate jobs getting scheduled with croniter 0.3.22 #189

Closed manango closed 5 years ago

manango commented 6 years ago

It looks like croniter 0.3.22 was released very recently. With that version, croniter.get_next() API behavior changed (looks like a bug) compared to 0.3.20 version. See https://github.com/taichino/croniter/issues/102.

Due to above croniter issue, if scheduler is running with less than 60 seconds interval, then there is possibility that scheduler incorrectly schedules "cron" based same job multiple times.

As an example, with croniter 0.3.22, let's say the job has cron configuration of '0,30 * * * *' (i.e. job is run at every 0 and 30 minutes). And let's say scheduler interval is 30 seconds. In that case:

Scheduler Run Time    | Scheduler Ran The Job?   | Next Job Schedule Time
-----------------------------------------------------------------------------
08:58:40              | No                       | 09:00:00
08:59:10              | No                       | 09:00:00
08:59:40              | No                       | 09:00:00
09:00:10              | Yes                      | 09:00:00    <- Since croniter.get_next() returns 09:00:00, job gets scheduled again at 9:00:00 incorrectly
09:00:40              | Yes                      | 09:00:00    <- Since croniter.get_next() returns 09:00:00, job gets scheduled again at 9:00:00 incorrectly
09:01:10              | Yes                      | 09:30:00
09:01:40              | No                       | 09:30:00
selwin commented 5 years ago

Fixed in https://github.com/taichino/croniter/pull/103