Skip to content

Commit 31aaaf0

Browse files
committed
fix: replace utcnow() with now(UTC).replace(tzinfo=None)
Replace utcnow() with timezone unaware now(UTC).replace(tzinfo=None)
1 parent 134c2eb commit 31aaaf0

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

rq_scheduler/scheduler.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import socket
66
from uuid import uuid4
77

8-
from datetime import datetime
8+
from datetime import datetime, UTC
99
from itertools import repeat
1010

1111
from rq.exceptions import NoSuchJobError
@@ -216,7 +216,7 @@ def enqueue_in(self, time_delta, func, *args, **kwargs):
216216
"""
217217
Similar to ``enqueue_at``, but accepts a timedelta instead of datetime object.
218218
The job's scheduled execution time will be calculated by adding the timedelta
219-
to datetime.utcnow().
219+
to datetime.now(UTC).
220220
"""
221221
timeout = kwargs.pop('timeout', None)
222222
job_id = kwargs.pop('job_id', None)
@@ -237,7 +237,7 @@ def enqueue_in(self, time_delta, func, *args, **kwargs):
237237
if at_front:
238238
job.enqueue_at_front = True
239239
self.connection.zadd(self.scheduled_jobs_key,
240-
{job.id: to_unix(datetime.utcnow() + time_delta)})
240+
{job.id: to_unix(datetime.now(UTC) + time_delta)})
241241
return job
242242

243243
def schedule(self, scheduled_time, func, args=None, kwargs=None,
@@ -391,7 +391,7 @@ def get_jobs_to_queue(self, with_times=False):
391391
If with_times is True a list of tuples consisting of the job instance and
392392
it's scheduled execution time is returned.
393393
"""
394-
return self.get_jobs(to_unix(datetime.utcnow()), with_times=with_times)
394+
return self.get_jobs(to_unix(datetime.now(UTC)), with_times=with_times)
395395

396396
def get_queue_for_job(self, job):
397397
"""
@@ -431,7 +431,7 @@ def enqueue_job(self, job):
431431
if job.meta['repeat'] == 0:
432432
return
433433
self.connection.zadd(self.scheduled_jobs_key,
434-
{job.id: to_unix(datetime.utcnow()) + int(interval)})
434+
{job.id: to_unix(datetime.now(UTC)) + int(interval)})
435435
elif cron_string:
436436
# If this is a repeat job and counter has reached 0, don't repeat
437437
if repeat is not None:

0 commit comments

Comments
 (0)