浏览代码

ExceptionInfo now passed to Task.on_retry/on_failure as einfo keyword argument.

Ask Solem 15 年之前
父节点
当前提交
471c4ea5d4
共有 2 个文件被更改,包括 18 次插入8 次删除
  1. 10 6
      celery/execute/trace.py
  2. 8 2
      celery/task/base.py

+ 10 - 6
celery/execute/trace.py

@@ -77,7 +77,6 @@ class TaskTrace(object):
 
     def handle_retry(self, exc, type_, tb, strtb):
         """Handle retry exception."""
-        self.task.on_retry(exc, self.task_id, self.args, self.kwargs)
 
         # Create a simpler version of the RetryTaskError that stringifies
         # the original exception instead of including the exception instance.
@@ -85,11 +84,16 @@ class TaskTrace(object):
         # guaranteeing pickleability.
         message, orig_exc = exc.args
         expanded_msg = "%s: %s" % (message, str(orig_exc))
-        return ExceptionInfo((type_,
-                              type_(expanded_msg, None),
-                              tb))
+        einfo = ExceptionInfo((type_,
+                               type_(expanded_msg, None),
+                               tb))
+        self.task.on_retry(exc, self.task_id,
+                           self.args, self.kwargs, einfo=einfo)
+        return einfo
 
     def handle_failure(self, exc, type_, tb, strtb):
         """Handle exception."""
-        self.task.on_failure(exc, self.task_id, self.args, self.kwargs)
-        return ExceptionInfo((type_, exc, tb))
+        einfo = ExceptionInfo((type_, exc, tb))
+        self.task.on_failure(exc, self.task_id,
+                             self.args, self.kwargs, einfo=info)
+        return einfo

+ 8 - 2
celery/task/base.py

@@ -412,7 +412,7 @@ class Task(object):
         """
         return BaseAsyncResult(task_id, backend=self.backend)
 
-    def on_retry(self, exc, task_id, args, kwargs):
+    def on_retry(self, exc, task_id, args, kwargs, einfo=None):
         """Retry handler.
 
         This is run by the worker when the task is to be retried.
@@ -422,12 +422,15 @@ class Task(object):
         :param args: Original arguments for the retried task.
         :param kwargs: Original keyword arguments for the retried task.
 
+        :keyword einfo: :class:`celery.datastructures.ExceptionInfo` instance,
+           containing the traceback.
+
         The return value of this handler is ignored.
 
         """
         pass
 
-    def on_failure(self, exc, task_id, args, kwargs):
+    def on_failure(self, exc, task_id, args, kwargs, einfo=None):
         """Error handler.
 
         This is run by the worker when the task fails.
@@ -437,6 +440,9 @@ class Task(object):
         :param args: Original arguments for the task that failed.
         :param kwargs: Original keyword arguments for the task that failed.
 
+        :keyword einfo: :class:`celery.datastructures.ExceptionInfo` instance,
+           containing the traceback.
+
         The return value of this handler is ignored.
 
         """