def on_failure(self, exc_info): """The handler used if the task raised an exception.""" state.task_ready(self) if self.task.acks_late: self.acknowledge() self.send_event("task-failed", uuid=self.task_id, exception=repr(exc_info.exception), traceback=exc_info.traceback) context = {"hostname": self.hostname, "id": self.task_id, "name": self.task_name, "exc": repr(exc_info.exception), "traceback": unicode(exc_info.traceback, 'utf-8'), "args": self.args, "kwargs": self.kwargs} 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: subject = self.email_subject.strip() % context body = self.email_body.strip() % context mail_admins(subject, body, fail_silently=True)
def send_error_email(self, task, context, exc, whitelist=None, enabled=False, fail_silently=True): if enabled and not task.disable_error_emails: if whitelist: if not isinstance(exc, tuple(whitelist)): return subject = self.email_subject.strip() % context body = self.email_body.strip() % context return mail_admins(subject, body, fail_silently=fail_silently)
def mail_admins(self, subject, body, fail_silently=False): return mail_admins(subject, body, fail_silently=fail_silently)