浏览代码

Added 'propagate=True' argument TaskSetResult.join: Disable to not re-raise exceptions occuring in subtasks

Ask Solem 14 年之前
父节点
当前提交
9dadb1c659
共有 1 个文件被更改,包括 26 次插入16 次删除
  1. 26 16
      celery/result.py

+ 26 - 16
celery/result.py

@@ -121,6 +121,11 @@ class BaseAsyncResult(object):
 
 
     @property
     @property
     def status(self):
     def status(self):
+        """Deprecated alias of :attr:`state`."""
+        return self.state
+
+    @property
+    def state(self):
         """The current status of the task.
         """The current status of the task.
 
 
         Can be one of the following:
         Can be one of the following:
@@ -301,22 +306,21 @@ class TaskSetResult(object):
                 elif result.status in states.PROPAGATE_STATES:
                 elif result.status in states.PROPAGATE_STATES:
                     raise result.result
                     raise result.result
 
 
-    def join(self, timeout=None):
-        """Gather the results for all of the tasks in the taskset,
-        and return a list with them ordered by the order of which they
-        were called.
+    def join(self, timeout=None, propagate=True):
+        """Gather the results of all tasks in the taskset,
+        and returns a list ordered by the order of the set.
+
+        :keyword timeout: The number of seconds to wait for results
+            before the operation times out.
 
 
-        :keyword timeout: The time in seconds, how long
-            it will wait for results, before the operation times out.
+        :keyword propagate: If any of the subtasks raises an exception, the
+            exception will be reraised.
 
 
         :raises celery.exceptions.TimeoutError: if ``timeout`` is not
         :raises celery.exceptions.TimeoutError: if ``timeout`` is not
             :const:`None` and the operation takes longer than ``timeout``
             :const:`None` and the operation takes longer than ``timeout``
             seconds.
             seconds.
 
 
-        If any of the tasks raises an exception, the exception
-        will be reraised by :meth:`join`.
-
-        :returns: list of return values for all tasks in the taskset.
+        :returns: list of return values for all subtasks in order.
 
 
         """
         """
 
 
@@ -329,17 +333,18 @@ class TaskSetResult(object):
 
 
         while True:
         while True:
             for position, pending_result in enumerate(self.subtasks):
             for position, pending_result in enumerate(self.subtasks):
-                if pending_result.status == states.SUCCESS:
+                state = pending_result.state
+                if state in states.READY_STATES:
+                    if propagate and state in states.PROPAGATE_STATES:
+                        raise pending_result.result
                     results[position] = pending_result.result
                     results[position] = pending_result.result
-                elif pending_result.status in states.PROPAGATE_STATES:
-                    raise pending_result.result
             if results.full():
             if results.full():
                 # Make list copy, so the returned type is not a position
                 # Make list copy, so the returned type is not a position
                 # queue.
                 # queue.
                 return list(results)
                 return list(results)
             else:
             else:
-                if timeout is not None and \
-                        time.time() >= time_start + timeout:
+                if (timeout is not None and
+                        time.time() >= time_start + timeout):
                     on_timeout()
                     on_timeout()
 
 
     def save(self, backend=None):
     def save(self, backend=None):
@@ -403,9 +408,14 @@ class EagerResult(BaseAsyncResult):
 
 
     @property
     @property
     def status(self):
     def status(self):
-        """The tasks status"""
+        """The tasks status (alias to :attr:`state`)."""
         return self._status
         return self._status
 
 
+    @property
+    def state(self):
+        """The tasks state."""
+        return self._state
+
     @property
     @property
     def traceback(self):
     def traceback(self):
         """The traceback if the task failed."""
         """The traceback if the task failed."""