Browse Source

Doesn't store errors if Task.ignore_result=True anymore, can enable the previous behaviour by setting CELERY_STORE_ERRORS_EVEN_IF_IGNORED

Ask Solem 15 years ago
parent
commit
0519be0eb3
3 changed files with 19 additions and 3 deletions
  1. 5 0
      celery/conf.py
  2. 9 3
      celery/worker/job.py
  3. 5 0
      docs/configuration.rst

+ 5 - 0
celery/conf.py

@@ -30,6 +30,7 @@ DEFAULT_CELERYMON_PID_FILE = "celerymon.pid"
 DEFAULT_CELERYMON_LOG_LEVEL = "INFO"
 DEFAULT_CELERYMON_LOG_LEVEL = "INFO"
 DEFAULT_CELERYMON_LOG_FILE = "celerymon.log"
 DEFAULT_CELERYMON_LOG_FILE = "celerymon.log"
 DEFAULT_SEND_EVENTS = False
 DEFAULT_SEND_EVENTS = False
+DEFAULT_STORE_ERRORS_EVEN_IF_IGNORED = False
 
 
 
 
 """
 """
@@ -375,3 +376,7 @@ Default is: ``False``.
 """
 """
 CELERY_SEND_EVENTS = getattr(settings, "CELERY_SEND_EVENTS",
 CELERY_SEND_EVENTS = getattr(settings, "CELERY_SEND_EVENTS",
                              DEFAULT_SEND_EVENTS)
                              DEFAULT_SEND_EVENTS)
+
+STORE_ERRORS_EVEN_IF_IGNORED = getattr(settings,
+                                       "CELERY_STORE_ERRORS_EVEN_IF_IGNORED",
+                                       DEFAULT_STORE_ERRORS_EVEN_IF_IGNORED)

+ 9 - 3
celery/worker/job.py

@@ -72,6 +72,10 @@ class WorkerTaskTrace(TaskTrace):
         self.loader = kwargs.pop("loader", current_loader)
         self.loader = kwargs.pop("loader", current_loader)
         super(WorkerTaskTrace, self).__init__(*args, **kwargs)
         super(WorkerTaskTrace, self).__init__(*args, **kwargs)
 
 
+        self._store_errors = True
+        if self.task.ignore_result:
+            self._store_errors = conf.STORE_ERRORS_EVEN_IF_IGNORED
+
     def execute_safe(self, *args, **kwargs):
     def execute_safe(self, *args, **kwargs):
         try:
         try:
             return self.execute(*args, **kwargs)
             return self.execute(*args, **kwargs)
@@ -105,7 +109,8 @@ class WorkerTaskTrace(TaskTrace):
     def handle_retry(self, exc, type_, tb, strtb):
     def handle_retry(self, exc, type_, tb, strtb):
         """Handle retry exception."""
         """Handle retry exception."""
         message, orig_exc = exc.args
         message, orig_exc = exc.args
-        self.task.backend.mark_as_retry(self.task_id, orig_exc, strtb)
+        if self._store_errors:
+            self.task.backend.mark_as_retry(self.task_id, orig_exc, strtb)
         return super(WorkerTaskTrace, self).handle_retry(exc, type_,
         return super(WorkerTaskTrace, self).handle_retry(exc, type_,
                                                          tb, strtb)
                                                          tb, strtb)
 
 
@@ -113,8 +118,9 @@ class WorkerTaskTrace(TaskTrace):
         """Handle exception."""
         """Handle exception."""
         # 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 = self.task.backend.mark_as_failure(self.task_id,
-                                                       exc, strtb)
+        if self._store_errors:
+            stored_exc = self.task.backend.mark_as_failure(self.task_id,
+                                                           exc, strtb)
         return super(WorkerTaskTrace, self).handle_failure(
         return super(WorkerTaskTrace, self).handle_failure(
                 stored_exc, type_, tb, strtb)
                 stored_exc, type_, tb, strtb)
 
 

+ 5 - 0
docs/configuration.rst

@@ -334,6 +334,11 @@ Task execution settings
 
 
     Default is ``pickle``.
     Default is ``pickle``.
 
 
+* CELERY_STORE_ERRORS_EVEN_IF_IGNORED
+
+    If set, the worker stores all task errors in the result store even if
+    ``Task.ignore_result`` is on.
+
 * CELERY_IMPORTS
 * CELERY_IMPORTS
     A sequence of modules to import when the celery daemon starts.  This is
     A sequence of modules to import when the celery daemon starts.  This is
     useful to add tasks if you are not using django or cannot use task
     useful to add tasks if you are not using django or cannot use task