Explorar o código

Merge commit 'upstream/master'

fredj %!s(int64=14) %!d(string=hai) anos
pai
achega
b073205bf2
Modificáronse 2 ficheiros con 10 adicións e 3 borrados
  1. 3 2
      celery/execute/__init__.py
  2. 7 1
      celery/messaging.py

+ 3 - 2
celery/execute/__init__.py

@@ -37,8 +37,9 @@ def apply_async(task, args=None, kwargs=None, countdown=None, eta=None,
       specified if ``countdown`` is also supplied. (Do not confuse this
       with the ``immediate`` setting, they are unrelated).
 
-    :keyword expires: A :class:`~datetime.datetime` object that describes
-      the absolute time and date of when the task should expire.
+    :keyword expires: Either a :class:`int`, describing the number of seconds,
+      or a :class:`~datetime.datetime` object that describes the absolute time
+      and date of when the task should expire.
       The task will not be executed after the expiration time.
 
     :keyword connection: Re-use existing broker connection instead

+ 7 - 1
celery/messaging.py

@@ -59,14 +59,20 @@ class TaskPublisher(Publisher):
         task_id = task_id or gen_unique_id()
         task_args = task_args or []
         task_kwargs = task_kwargs or {}
+        now = None
         if countdown: # Convert countdown to ETA.
-            eta = datetime.now() + timedelta(seconds=countdown)
+            now = datetime.now()
+            eta = now + timedelta(seconds=countdown)
 
         if not isinstance(task_args, (list, tuple)):
             raise ValueError("task args must be a list or tuple")
         if not isinstance(task_kwargs, dict):
             raise ValueError("task kwargs must be a dictionary")
 
+        if isinstance(expires, int):
+            now = now or datetime.now()
+            expires = now + timedelta(seconds=expires)
+
         message_data = {
             "task": task_name,
             "id": task_id,