@@ -414,15 +414,19 @@ def on_failure(self, exc_info):
414414 self .logger .error (self .error_msg .strip () % context )
415415
416416 task_obj = tasks .get (self .task_name , object )
417- send_error_email = conf .CELERY_SEND_TASK_ERROR_EMAILS and not \
418- task_obj .disable_error_emails and not any (
419- isinstance (exc_info .exception , whexc )
420- for whexc in
421- conf .CELERY_TASK_ERROR_WHITELIST )
422- if send_error_email :
417+ self .send_error_email (task_obj , context , exc_info .exception )
418+
419+ def send_error_email (self , task , context , exc ,
420+ whitelist = conf .CELERY_TASK_ERROR_WHITELIST ,
421+ enabled = conf .CELERY_SEND_TASK_ERROR_EMAILS ,
422+ fail_silently = True ):
423+ if enabled and not task .disable_error_emails :
424+ if whitelist is not None :
425+ if not isinstance (exc , tuple (whitelist )):
426+ return
423427 subject = self .email_subject .strip () % context
424428 body = self .email_body .strip () % context
425- mail_admins (subject , body , fail_silently = True )
429+ return mail_admins (subject , body , fail_silently = fail_silently )
426430
427431 def __repr__ (self ):
428432 return '<%s: {name:"%s", id:"%s", args:"%s", kwargs:"%s"}>' % (
0 commit comments