浏览代码

@task(trail=False) can now be used to disable result.children trails

Ask Solem 11 年之前
父节点
当前提交
32e0fbfbad
共有 3 个文件被更改,包括 15 次插入4 次删除
  1. 1 1
      celery/app/builtins.py
  2. 13 2
      celery/app/task.py
  3. 1 1
      celery/task/sets.py

+ 1 - 1
celery/app/builtins.py

@@ -179,7 +179,7 @@ def add_group_task(app):
                                    add_to_parent=False) for stask in taskit]
             parent = get_current_worker_task()
             if parent:
-                parent.request.children.append(result)
+                parent.add_trail(result)
             return result
 
         def prepare(self, options, tasks, args, **kwargs):

+ 13 - 2
celery/app/task.py

@@ -206,6 +206,11 @@ class Task(object):
     #: setting.
     ignore_result = None
 
+    #: If enabled the request will keep track of subtasks started by
+    #: this task, and this information will be sent with the result
+    #: (``result.children``).
+    trail = True
+
     #: When enabled errors will be stored even if the task is otherwise
     #: configured to ignore results.
     store_errors_even_if_ignored = None
@@ -462,7 +467,8 @@ class Task(object):
         :keyword add_to_parent: If set to True (default) and the task
             is applied while executing another task, then the result
             will be appended to the parent tasks ``request.children``
-            attribute.
+            attribute.  Trailing can also be disabled by default using the
+            :attr:`trail` attribute
         :keyword publisher: Deprecated alias to ``producer``.
 
         Also supports all keyword arguments supported by
@@ -503,7 +509,7 @@ class Task(object):
         if add_to_parent:
             parent = get_current_worker_task()
             if parent:
-                parent.request.children.append(result)
+                parent.add_trail(result)
         return result
 
     def subtask_from_request(self, request=None, args=None, kwargs=None,
@@ -801,6 +807,11 @@ class Task(object):
                 not getattr(self, 'disable_error_emails', None):
             self.ErrorMail(self, **kwargs).send(context, exc)
 
+    def add_trail(self, result):
+        if self.trail:
+            self.request.children.append(result)
+        return result
+
     def push_request(self, *args, **kwargs):
         self.request_stack.push(Context(*args, **kwargs))
 

+ 1 - 1
celery/task/sets.py

@@ -58,7 +58,7 @@ class TaskSet(list):
             result = app.TaskSetResult(setid, results)
             parent = get_current_worker_task()
             if parent:
-                parent.request.children.append(result)
+                parent.add_trail(result)
             return result
 
     def _async_results(self, taskset_id, publisher):