Browse Source

Convert stored tracebacks to strings

Ask Solem 15 years ago
parent
commit
5f09ce1469
2 changed files with 15 additions and 7 deletions
  1. 5 3
      celery/execute.py
  2. 10 4
      celery/worker/job.py

+ 5 - 3
celery/execute.py

@@ -7,6 +7,7 @@ from celery.utils import gen_unique_id
 from functools import partial as curry
 from functools import partial as curry
 from datetime import datetime, timedelta
 from datetime import datetime, timedelta
 from multiprocessing import get_logger
 from multiprocessing import get_logger
+import sys
 import traceback
 import traceback
 import inspect
 import inspect
 
 
@@ -155,10 +156,11 @@ def apply(task, args, kwargs, **options):
     try:
     try:
         ret_value = task(*args, **kwargs)
         ret_value = task(*args, **kwargs)
         status = "DONE"
         status = "DONE"
-        tb = None
+        strtb = None
     except Exception, exc:
     except Exception, exc:
+        type_, value_, tb = sys.exc_info()
+        strtb = "\n".join(traceback.format_exception(type_, value_, tb))
         ret_value = exc
         ret_value = exc
-        tb = traceback.format_stack()
         status = "FAILURE"
         status = "FAILURE"
 
 
-    return EagerResult(task_id, ret_value, status, traceback=tb)
+    return EagerResult(task_id, ret_value, status, traceback=strtb)

+ 10 - 4
celery/worker/job.py

@@ -43,6 +43,10 @@ def jail(task_id, task_name, func, args, kwargs):
     If the call was successful, it saves the result to the task result
     If the call was successful, it saves the result to the task result
     backend, and sets the task status to ``"DONE"``.
     backend, and sets the task status to ``"DONE"``.
 
 
+    If the call raises :exc:`celery.task.base.RetryTaskError`, it extracts
+    the original exception, uses that as the result and sets the task status
+    to ``"RETRY"``.
+
     If the call results in an exception, it saves the exception as the task
     If the call results in an exception, it saves the exception as the task
     result, and sets the task status to ``"FAILURE"``.
     result, and sets the task status to ``"FAILURE"``.
 
 
@@ -73,12 +77,13 @@ def jail(task_id, task_name, func, args, kwargs):
         raise
         raise
     except RetryTaskError, exc:
     except RetryTaskError, exc:
         ### Task is to be retried.
         ### Task is to be retried.
-        type_, _, tb = sys.exc_info()
+        type_, value_, tb = sys.exc_info()
+        strtb = "\n".join(traceback.format_exception(type_, value_, tb))
 
 
         # RetryTaskError stores both a small message describing the retry
         # RetryTaskError stores both a small message describing the retry
         # and the original exception.
         # and the original exception.
         message, orig_exc = exc.args
         message, orig_exc = exc.args
-        default_backend.mark_as_retry(task_id, orig_exc, tb)
+        default_backend.mark_as_retry(task_id, orig_exc, strtb)
 
 
         # Create a simpler version of the RetryTaskError that stringifies
         # Create a simpler version of the RetryTaskError that stringifies
         # the original exception instead of including the exception instance.
         # the original exception instead of including the exception instance.
@@ -90,11 +95,12 @@ def jail(task_id, task_name, func, args, kwargs):
                                 tb))
                                 tb))
     except Exception, exc:
     except Exception, exc:
         ### Task ended in failure.
         ### Task ended in failure.
-        type_, _, tb = sys.exc_info()
+        type_, value_, tb = sys.exc_info()
+        strtb = "\n".join(traceback.format_exception(type_, value_, tb))
 
 
         # mark_as_failure returns an exception that is guaranteed to
         # mark_as_failure returns an exception that is guaranteed to
         # be pickleable.
         # be pickleable.
-        stored_exc = default_backend.mark_as_failure(task_id, exc, tb)
+        stored_exc = default_backend.mark_as_failure(task_id, exc, strtb)
 
 
         # wrap exception info + traceback and return it to caller.
         # wrap exception info + traceback and return it to caller.
         retval = ExceptionInfo((type_, stored_exc, tb))
         retval = ExceptionInfo((type_, stored_exc, tb))