rq / rq-scheduler

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

Jobs dispatched EARLIER than scheduled #246

Closed taewookim closed 4 years ago

taewookim commented 4 years ago

I'm seeing that jobs in scheduler get executed EARLIER than as defined in "enqueue_at".

I thought it was issue with UTC datetime, but that doesnt' seem to be the issue.

Not sure if this matters but I have multiple schedulers and multiple workers... (as recommended in the docs).

According to this doc:

Note that if you pass in a naive datetime object, RQ will automatically convert it to the local timezone.

However, comment in this repo says

scheduler.enqueue_at(datetime(2020, 1, 1), func) # Date time should be in UTC

Bit confused which im supposed to pass

Any ideas?

taewookim commented 4 years ago

Example:

================================= At, 2020-08-25 21:51:00+00:00, I add 1 job to queue [job 1] send_date: 2020-08-25 21:55:00+00:00

================================= At 2020-08-25 21:52:00+00:00, two things happen 1) I add 2 more jobs

[job 1] send_date: 2020-08-25 21:55:00+00:00 [job 2] send_date: 2020-08-25 22:00:00+00:00 [job 3] send_date: 2020-08-25 22:05:00+00:00

2) Job 1 is launched

================================= At 2020-08-25 21:53:00+00:00

Job2 is launched

================================= At 2020-08-25 21:54:00+00:00

Job3 is launched

IN all cases, the jobs are launched AHEAD of their scheduled time

taewookim commented 4 years ago

SO post

taewookim commented 4 years ago

This was happening b/c i was passing naive datetime but RQ scheduler was expecting timezone aware datetime.

petervtzand commented 4 years ago

👍 It was probably better to raise an error when passing a non timezone aware datetime.