Skip to content

Commit 4dd3826

Browse files
Merge pull request #9 from milind-shakya-sp/fix_interval_schedulers
Fix interval schedulers
2 parents 4e9e3b5 + db9f2e1 commit 4dd3826

File tree

7 files changed

+34
-10
lines changed

7 files changed

+34
-10
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 1.3.0
2+
current_version = 1.4.0
33
commit = True
44
tag = True
55
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(?P<releaselevel>[a-z]+)?

Changelog

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
Change history
55
================
66

7+
.. _version-1.4.0:
8+
9+
1.4.0
10+
=====
11+
:release-date: 2018-12-09 1:30 p.m. UTC+2:00
12+
:release-by: Omer Katz
13+
14+
- Fix migrations dependencies.
15+
- Added the DJANGO_CELERY_BEAT_TZ_AWARE setting.
16+
717
.. _version-1.3.0:
818

919
1.3.0

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
|build-status| |coverage| |license| |wheel| |pyversion| |pyimp|
1010

11-
:Version: 1.3.0
11+
:Version: 1.4.0
1212
:Web: http://django-celery-beat.readthedocs.io/
1313
:Download: http://pypi.python.org/pypi/django-celery-beat
1414
:Source: http://github.com/celery/django-celery-beat

django_celery_beat/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from collections import namedtuple
1212

13-
__version__ = '1.3.0+singleplatform.1'
13+
__version__ = '1.4.0+singleplatform.1'
1414
__author__ = 'Ask Solem'
1515
__contact__ = '[email protected]'
1616
__homepage__ = 'https://github.com/celery/django-celery-beat'

django_celery_beat/models.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ def __str__(self):
108108
)
109109

110110

111+
class TZNaiveSchedule(schedules.schedule):
112+
113+
def maybe_make_aware(self, dt):
114+
"""
115+
Overriding the base method, to be a no-op and returning the dt as is.
116+
"""
117+
return dt
118+
119+
111120
@python_2_unicode_compatible
112121
class IntervalSchedule(models.Model):
113122
"""Schedule executing every n seconds."""
@@ -134,10 +143,15 @@ class Meta:
134143

135144
@property
136145
def schedule(self):
137-
return schedules.schedule(
146+
_schedule = TZNaiveSchedule(
138147
timedelta(**{self.period: self.every}),
139-
nowfun=lambda: make_aware(now())
140148
)
149+
if getattr(settings, 'DJANGO_CELERY_BEAT_TZ_AWARE', True):
150+
_schedule = schedules.schedule(
151+
timedelta(**{self.period: self.every}),
152+
nowfun=lambda: make_aware(now())
153+
)
154+
return _schedule
141155

142156
@classmethod
143157
def from_schedule(cls, schedule, period=SECONDS):
@@ -218,7 +232,7 @@ def schedule(self):
218232
day_of_month=self.day_of_month,
219233
month_of_year=self.month_of_year,
220234
)
221-
if settings.DJANGO_CELERY_BEAT_TZ_AWARE:
235+
if getattr(settings, 'DJANGO_CELERY_BEAT_TZ_AWARE', True):
222236
crontab = TzAwareCrontab(
223237
minute=self.minute,
224238
hour=self.hour,

django_celery_beat/schedulers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def __init__(self, model, app=None):
9494

9595
last_run_at = model.last_run_at
9696

97-
if settings.DJANGO_CELERY_BEAT_TZ_AWARE:
97+
if getattr(settings, 'DJANGO_CELERY_BEAT_TZ_AWARE', True):
9898
last_run_at = make_aware(last_run_at)
9999

100100
self.last_run_at = last_run_at
@@ -133,7 +133,7 @@ def _default_now(self):
133133
# The PyTZ datetime must be localised for the Django-Celery-Beat
134134
# scheduler to work. Keep in mind that timezone arithmatic
135135
# with a localized timezone may be inaccurate.
136-
if settings.DJANGO_CELERY_BEAT_TZ_AWARE:
136+
if getattr(settings, 'DJANGO_CELERY_BEAT_TZ_AWARE', True):
137137
now = now.tzinfo.localize(now.replace(tzinfo=None))
138138
return now
139139

@@ -151,7 +151,7 @@ def save(self):
151151
for field in self.save_fields:
152152
setattr(obj, field, getattr(self.model, field))
153153

154-
if not settings.DJANGO_CELERY_BEAT_TZ_AWARE:
154+
if not getattr(settings, 'DJANGO_CELERY_BEAT_TZ_AWARE', True):
155155
obj.last_run_at = datetime.datetime.now()
156156

157157
obj.save()

docs/includes/introduction.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
:Version: 1.3.0
1+
:Version: 1.4.0
22
:Web: http://django-celery-beat.readthedocs.io/
33
:Download: http://pypi.python.org/pypi/django-celery-beat
44
:Source: http://github.com/celery/django-celery-beat

0 commit comments

Comments
 (0)