Просмотр исходного кода

Pass task_id, args, kwargs to the handlers Task.on_sucess, .on_retry,
.on_failure

Ask Solem 15 лет назад
Родитель
Сommit
fb17ee7a74
3 измененных файлов с 16 добавлено и 6 удалено
  1. 3 3
      celery/execute.py
  2. 12 3
      celery/task/base.py
  3. 1 0
      docs/cookbook/index.rst

+ 3 - 3
celery/execute.py

@@ -264,7 +264,7 @@ class ExecuteWrapper(object):
 
         # Run success handler last to be sure the status is saved.
         success_handler = getattr(self.fun, "on_success", noop)
-        success_handler(retval)
+        success_handler(retval, self.task_id, self.args, self.kwargs)
 
         return retval
 
@@ -290,7 +290,7 @@ class ExecuteWrapper(object):
 
         # Run retry handler last to be sure the status is saved.
         retry_handler = getattr(self.fun, "on_retry", noop)
-        retry_handler(exc)
+        retry_handler(exc, self.task_id, self.args, self.kwargs)
 
         return retval
 
@@ -309,6 +309,6 @@ class ExecuteWrapper(object):
 
         # Run error handler last to be sure the status is stored.
         error_handler = getattr(self.fun, "on_failure", noop)
-        error_handler(stored_exc)
+        error_handler(stored_exc, self.task_id, self.args, self.kwargs)
 
         return retval

+ 12 - 3
celery/task/base.py

@@ -335,32 +335,41 @@ class Task(object):
             message = "Retry in %d seconds." % options["countdown"]
             raise RetryTaskError(message, exc)
 
-    def on_retry(self, exc):
+    def on_retry(self, exc, task_id, args, kwargs):
         """Retry handler.
 
         This is run by the worker when the task is to be retried.
 
         :param exc: The exception sent to :meth:`retry`.
+        :param task_id: Unique id of the retried task.
+        :param args: Original arguments for the retried task.
+        :param kwargs: Original keyword arguments for the retried task.
 
         """
         pass
 
-    def on_failure(self, exc):
+    def on_failure(self, exc, task_id, args, kwargs):
         """Error handler.
 
         This is run by the worker when the task fails.
 
         :param exc: The exception raised by the task.
+        :param task_id: Unique id of the failed task.
+        :param args: Original arguments for the task that failed.
+        :param kwargs: Original keyword arguments for the task that failed.
 
         """
         pass
 
-    def on_success(self, retval):
+    def on_success(self, retval, task_id, args, kwargs):
         """Success handler.
 
         This is run by the worker when the task executed successfully.
 
         :param retval: The return value of the task.
+        :param task_id: Unique id of the executed task.
+        :param args: Original arguments for the executed task.
+        :param kwargs: Original keyword arguments for the executed task.
 
         """
         pass

+ 1 - 0
docs/cookbook/index.rst

@@ -5,6 +5,7 @@
 .. toctree::
     :maxdepth: 2
 
+    tasks
     task-retries
 
 This page contains common recipes and techniques.