Parcourir la source

Worker crashes if CELERY_TASK_ERROR_WHITELIST is not iterable

Ask Solem il y a 14 ans
Parent
commit
6e70ce0a77
1 fichiers modifiés avec 11 ajouts et 7 suppressions
  1. 11 7
      celery/worker/job.py

+ 11 - 7
celery/worker/job.py

@@ -434,15 +434,19 @@ class TaskRequest(object):
         self.logger.error(self.error_msg.strip() % context)
 
         task_obj = tasks.get(self.task_name, object)
-        send_error_email = conf.CELERY_SEND_TASK_ERROR_EMAILS and not \
-                                task_obj.disable_error_emails and not any(
-                                    isinstance(exc_info.exception, whexc)
-                                    for whexc in
-                                    conf.CELERY_TASK_ERROR_WHITELIST)
-        if send_error_email:
+        self.send_error_email(task_obj, context, exc_info.exception)
+
+    def send_error_email(self, task, context, exc,
+            whitelist=conf.CELERY_TASK_ERROR_WHITELIST,
+            enabled=conf.CELERY_SEND_TASK_ERROR_EMAILS,
+            fail_silently=True):
+        if enabled and not task.disable_error_emails:
+            if whitelist is not None:
+                if not isinstance(exc, tuple(whitelist)):
+                    return
             subject = self.email_subject.strip() % context
             body = self.email_body.strip() % context
-            mail_admins(subject, body, fail_silently=True)
+            return mail_admins(subject, body, fail_silently=fail_silently)
 
     def __repr__(self):
         return '<%s: {name:"%s", id:"%s", args:"%s", kwargs:"%s"}>' % (