Browse Source

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

Ask Solem 11 năm trước cách đây
mục cha
commit
32e0fbfbad
3 tập tin đã thay đổi với 15 bổ sung4 xóa
  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]
                                    add_to_parent=False) for stask in taskit]
             parent = get_current_worker_task()
             parent = get_current_worker_task()
             if parent:
             if parent:
-                parent.request.children.append(result)
+                parent.add_trail(result)
             return result
             return result
 
 
         def prepare(self, options, tasks, args, **kwargs):
         def prepare(self, options, tasks, args, **kwargs):

+ 13 - 2
celery/app/task.py

@@ -206,6 +206,11 @@ class Task(object):
     #: setting.
     #: setting.
     ignore_result = None
     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
     #: When enabled errors will be stored even if the task is otherwise
     #: configured to ignore results.
     #: configured to ignore results.
     store_errors_even_if_ignored = None
     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
         :keyword add_to_parent: If set to True (default) and the task
             is applied while executing another task, then the result
             is applied while executing another task, then the result
             will be appended to the parent tasks ``request.children``
             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``.
         :keyword publisher: Deprecated alias to ``producer``.
 
 
         Also supports all keyword arguments supported by
         Also supports all keyword arguments supported by
@@ -503,7 +509,7 @@ class Task(object):
         if add_to_parent:
         if add_to_parent:
             parent = get_current_worker_task()
             parent = get_current_worker_task()
             if parent:
             if parent:
-                parent.request.children.append(result)
+                parent.add_trail(result)
         return result
         return result
 
 
     def subtask_from_request(self, request=None, args=None, kwargs=None,
     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):
                 not getattr(self, 'disable_error_emails', None):
             self.ErrorMail(self, **kwargs).send(context, exc)
             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):
     def push_request(self, *args, **kwargs):
         self.request_stack.push(Context(*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)
             result = app.TaskSetResult(setid, results)
             parent = get_current_worker_task()
             parent = get_current_worker_task()
             if parent:
             if parent:
-                parent.request.children.append(result)
+                parent.add_trail(result)
             return result
             return result
 
 
     def _async_results(self, taskset_id, publisher):
     def _async_results(self, taskset_id, publisher):