Browse Source

Task: Add attribute "disable_error_emails" to disable sending error emails for
that task.

Ask Solem 16 years ago
parent
commit
a7ff8d9546
2 changed files with 10 additions and 1 deletions
  1. 6 0
      celery/task.py
  2. 4 1
      celery/worker.py

+ 6 - 0
celery/task.py

@@ -182,6 +182,11 @@ class Task(object):
     
         The message priority. A number from ``0`` to ``9``.
 
+    .. attribute:: disable_error_emails
+
+        Disable all error e-mails for this task (only applicable if
+        ``settings.SEND_CELERY_ERROR_EMAILS`` is on).
+
     :raises NotImplementedError: if the :attr:`name` attribute is not set.
 
     The resulting class is callable, which if called will apply the
@@ -224,6 +229,7 @@ class Task(object):
     immediate = False
     mandatory = False
     priority = None
+    disable_error_emails = False
 
     def __init__(self):
         if not self.name:

+ 4 - 1
celery/worker.py

@@ -251,7 +251,10 @@ class TaskWrapper(object):
         }
         self.logger.error(self.fail_msg.strip() % context)
 
-        if SEND_CELERY_TASK_ERROR_EMAILS:
+        task_obj = tasks.get(task_name, object)
+        send_error_email = SEND_CELERY_TASK_ERROR_EMAILS or not \
+                getattr(task_obj, "disable_error_emails", False)
+        if send_error_email:
             subject = self.fail_email_subject.strip() % context
             body = self.fail_email_body.strip() % context
             mail_admins(subject, body, fail_silently=True)