Skip to content

Commit 840047f

Browse files
dmitry-krasilnikovask
authored andcommitted
Made use of CELERY_ENABLE_UTC
1 parent dfbf20e commit 840047f

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

djcelery/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from . import managers
1818
from .picklefield import PickledObjectField
19-
from .utils import now
19+
from .utils import fromtimestamp, now
2020
from .compat import python_2_unicode_compatible
2121

2222
TASK_STATE_CHOICES = zip(states.ALL_STATES, states.ALL_STATES)
@@ -360,11 +360,11 @@ class Meta:
360360

361361
def save(self, *args, **kwargs):
362362
if self.eta is not None:
363-
self.eta = datetime.utcfromtimestamp(float('%d.%s' % (
363+
self.eta = fromtimestamp(float('%d.%s' % (
364364
mktime(self.eta.timetuple()), self.eta.microsecond,
365365
)))
366366
if self.expires is not None:
367-
self.expires = datetime.utcfromtimestamp(float('%d.%s' % (
367+
self.expires = fromtimestamp(float('%d.%s' % (
368368
mktime(self.expires.timetuple()), self.expires.microsecond,
369369
)))
370370
super(TaskState, self).save(*args, **kwargs)

djcelery/snapshot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from celery.utils.timeutils import maybe_iso8601
1414

1515
from .models import WorkerState, TaskState
16-
from .utils import maybe_make_aware
16+
from .utils import fromtimestamp, maybe_make_aware
1717

1818
WORKER_UPDATE_FREQ = 60 # limit worker timestamp write freq.
1919
SUCCESS_STATES = frozenset([states.SUCCESS])
@@ -33,7 +33,7 @@
3333

3434
def aware_tstamp(secs):
3535
"""Event timestamps uses the local timezone."""
36-
return maybe_make_aware(datetime.utcfromtimestamp(secs))
36+
return maybe_make_aware(fromtimestamp(secs))
3737

3838

3939
class Camera(Polaroid):

djcelery/utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,10 @@ def is_database_scheduler(scheduler):
9393
from kombu.utils import symbol_by_name
9494
from .schedulers import DatabaseScheduler
9595
return issubclass(symbol_by_name(scheduler), DatabaseScheduler)
96+
97+
98+
def fromtimestamp(value):
99+
if getattr(settings, 'CELERY_ENABLE_UTC', False):
100+
return datetime.utcfromtimestamp(value)
101+
else:
102+
return datetime.fromtimestamp(value)

0 commit comments

Comments
 (0)