|
@@ -18,7 +18,7 @@ from ..execute.trace import TaskTrace
|
|
|
from ..utils import (noop, kwdict, fun_takes_kwargs,
|
|
|
get_symbol_by_name, truncate_text)
|
|
|
from ..utils.encoding import safe_repr, safe_str, default_encoding
|
|
|
-from ..utils.timeutils import maybe_iso8601
|
|
|
+from ..utils.timeutils import maybe_iso8601, timezone
|
|
|
|
|
|
from . import state
|
|
|
|
|
@@ -253,7 +253,7 @@ class TaskRequest(object):
|
|
|
on_ack=noop, retries=0, delivery_info=None, hostname=None,
|
|
|
email_subject=None, email_body=None, logger=None,
|
|
|
eventer=None, eta=None, expires=None, app=None,
|
|
|
- taskset_id=None, chord=None, **opts):
|
|
|
+ taskset_id=None, chord=None, tz=0x1, **opts):
|
|
|
self.app = app_or_default(app)
|
|
|
self.task_name = task_name
|
|
|
self.task_id = task_id
|
|
@@ -277,6 +277,15 @@ class TaskRequest(object):
|
|
|
if self.task.ignore_result:
|
|
|
self._store_errors = self.task.store_errors_even_if_ignored
|
|
|
|
|
|
+ # timezone means the message is timezone-aware, and the only timezone
|
|
|
+ # supported at this point is UTC.
|
|
|
+ self.tzlocal = timezone.tz_or_local(self.app.conf.CELERY_TIMEZONE)
|
|
|
+ tz = tz and timezone.utc or self.tzlocal
|
|
|
+ if self.eta is not None:
|
|
|
+ self.eta = timezone.to_local(self.eta, self.tzlocal, tz)
|
|
|
+ if self.expires is not None:
|
|
|
+ self.expires = timezone.to_local(self.expires, self.tzlocal, tz)
|
|
|
+
|
|
|
@classmethod
|
|
|
def from_message(cls, message, body, on_ack=noop, **kw):
|
|
|
"""Create request from a task message.
|
|
@@ -302,7 +311,10 @@ class TaskRequest(object):
|
|
|
retries=body.get("retries", 0),
|
|
|
eta=maybe_iso8601(body.get("eta")),
|
|
|
expires=maybe_iso8601(body.get("expires")),
|
|
|
- on_ack=on_ack, delivery_info=delivery_info, **kw)
|
|
|
+ on_ack=on_ack,
|
|
|
+ delivery_info=delivery_info,
|
|
|
+ tz=body.get("tz", None),
|
|
|
+ **kw)
|
|
|
|
|
|
def get_instance_attrs(self, loglevel, logfile):
|
|
|
return {"logfile": logfile, "loglevel": loglevel,
|
|
@@ -393,7 +405,7 @@ class TaskRequest(object):
|
|
|
|
|
|
def maybe_expire(self):
|
|
|
"""If expired, mark the task as revoked."""
|
|
|
- if self.expires and datetime.now() > self.expires:
|
|
|
+ if self.expires and datetime.now(self.tzlocal) > self.expires:
|
|
|
state.revoked.add(self.task_id)
|
|
|
if self._store_errors:
|
|
|
self.task.backend.mark_as_revoked(self.task_id)
|