예제 #1
0
파일: job.py 프로젝트: sebleier/celery
    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)
예제 #2
0
 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 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)
예제 #4
0
 def mail_admins(self, subject, body, fail_silently=False):
     return mail_admins(subject, body, fail_silently=fail_silently)
예제 #5
0
 def mail_admins(self, subject, body, fail_silently=False):
     return mail_admins(subject, body, fail_silently=fail_silently)