Skip to content

Commit 4e67af3

Browse files
committed
Fixes timezone issues with Database Scheduler
1 parent 83c7bff commit 4e67af3

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

djcelery/models.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ def schedule(self):
148148
hour=self.hour,
149149
day_of_week=self.day_of_week,
150150
day_of_month=self.day_of_month,
151-
month_of_year=self.month_of_year,
152-
nowfun=now)
151+
month_of_year=self.month_of_year)
153152

154153
@classmethod
155154
def from_schedule(cls, schedule):

djcelery/schedulers.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from warnings import warn
66

77
from anyjson import deserialize, serialize
8+
from celery import current_app
89
from celery import schedules
910
from celery.beat import Scheduler, ScheduleEntry
1011
from celery.utils.encoding import safe_str, safe_repr
@@ -15,7 +16,7 @@
1516

1617
from .models import (PeriodicTask, PeriodicTasks,
1718
CrontabSchedule, IntervalSchedule)
18-
from .utils import DATABASE_ERRORS, now
19+
from .utils import DATABASE_ERRORS
1920

2021
# This scheduler must wake up more frequently than the
2122
# regular of 5 minutes because it needs to take external
@@ -29,6 +30,7 @@ class ModelEntry(ScheduleEntry):
2930
save_fields = ["last_run_at", "total_run_count", "no_changes"]
3031

3132
def __init__(self, model):
33+
self.app = current_app._get_current_object()
3234
self.name = model.name
3335
self.task = model.task
3436
self.schedule = model.schedule
@@ -59,10 +61,10 @@ def is_due(self):
5961
return self.schedule.is_due(self.last_run_at)
6062

6163
def _default_now(self):
62-
return now()
64+
return self.app.now()
6365

6466
def next(self):
65-
self.model.last_run_at = now()
67+
self.model.last_run_at = self.app.now()
6668
self.model.total_run_count += 1
6769
self.model.no_changes = True
6870
return self.__class__(self.model)
@@ -158,7 +160,7 @@ def schedule_changed(self):
158160
except DATABASE_ERRORS, exc:
159161
warn(RuntimeWarning("Database gave error: %r" % (exc, )))
160162
return False
161-
self._last_timestamp = now()
163+
self._last_timestamp = self.app.now()
162164
return True
163165

164166
def reserve(self, entry):
@@ -207,7 +209,7 @@ def install_default_entries(self, data):
207209
if self.app.conf.CELERY_TASK_RESULT_EXPIRES:
208210
entries.setdefault("celery.backend_cleanup", {
209211
"task": "celery.backend_cleanup",
210-
"schedule": schedules.crontab("0", "4", "*", nowfun=now),
212+
"schedule": schedules.crontab("0", "4", "*"),
211213
"options": {"expires": 12 * 3600}})
212214
self.update_from_dict(entries)
213215

0 commit comments

Comments
 (0)