Esempio n. 1
0
    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)

        # This is a special case as the process would not have had
        # time to write the result.
        if isinstance(exc_info.exception, WorkerLostError):
            self.task.backend.mark_as_failure(self.task_id,
                                              exc_info.exception)

        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)
        self.send_error_email(task_obj, context, exc_info.exception,
                              enabled=task_obj.send_error_emails,
                              whitelist=task_obj.error_whitelist)
Esempio n. 2
0
    def on_failure(self, exc_info):
        """The handler used if the task raised an exception."""

        self.send_event("task-failed", uuid=self.task_id,
                                       exception=exc_info.exception,
                                       traceback=exc_info.traceback)

        context = {
            "hostname": socket.gethostname(),
            "id": self.task_id,
            "name": self.task_name,
            "exc": exc_info.exception,
            "traceback": exc_info.traceback,
            "args": self.args,
            "kwargs": self.kwargs,
        }
        self.logger.error(self.fail_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
        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)
Esempio n. 3
0
    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 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)
        self.send_error_email(task_obj,
                              context,
                              exc_info.exception,
                              whitelist=conf.CELERY_TASK_ERROR_WHITELIST,
                              enabled=conf.CELERY_SEND_TASK_ERROR_EMAILS)
Esempio n. 5
0
 def test_on_chord_apply(self, unlock="celery.chord_unlock"):
     from celery.registry import tasks
     p, tasks[unlock] = tasks.get(unlock), Mock()
     try:
         b.on_chord_apply("dakj221", "sdokqweok")
         self.assertTrue(tasks[unlock].apply_async.call_count)
     finally:
         tasks[unlock] = p
Esempio n. 6
0
 def test_on_chord_apply(self, unlock="celery.chord_unlock"):
     from celery.registry import tasks
     p, tasks[unlock] = tasks.get(unlock), Mock()
     try:
         b.on_chord_apply("dakj221", "sdokqweok")
         self.assertTrue(tasks[unlock].apply_async.call_count)
     finally:
         tasks[unlock] = p
Esempio n. 7
0
File: job.py Progetto: tobych/celery
    def on_failure(self, exc_info):
        """Handler called if the task raised an exception."""
        state.task_ready(self)

        if self.task.acks_late:
            self.acknowledge()

        if isinstance(exc_info.exception, RetryTaskError):
            return self.on_retry(exc_info)

        # This is a special case as the process would not have had
        # time to write the result.
        if isinstance(exc_info.exception, WorkerLostError):
            if self._store_errors:
                self.task.backend.mark_as_failure(self.task_id,
                                                  exc_info.exception)

        self.send_event("task-failed",
                        uuid=self.task_id,
                        exception=safe_repr(exc_info.exception),
                        traceback=safe_str(exc_info.traceback))

        context = {
            "hostname": self.hostname,
            "id": self.task_id,
            "name": self.task_name,
            "exc": safe_repr(exc_info.exception),
            "traceback": safe_str(exc_info.traceback),
            "args": self.args,
            "kwargs": self.kwargs
        }

        log_with_extra(self.logger,
                       logging.ERROR,
                       self.error_msg.strip() % context,
                       exc_info=exc_info,
                       extra={
                           "data": {
                               "hostname": self.hostname,
                               "id": self.task_id,
                               "name": self.task_name
                           }
                       })

        task_obj = tasks.get(self.task_name, object)
        self.send_error_email(task_obj,
                              context,
                              exc_info.exception,
                              enabled=task_obj.send_error_emails,
                              whitelist=task_obj.error_whitelist)
Esempio n. 8
0
    def on_failure(self, exc_info):
        """Handler called if the task raised an exception."""
        state.task_ready(self)

        if self.task.acks_late:
            self.acknowledge()

        if isinstance(exc_info.exception, RetryTaskError):
            return self.on_retry(exc_info)

        # This is a special case as the process would not have had
        # time to write the result.
        if isinstance(exc_info.exception, WorkerLostError):
            if self._store_errors:
                self.task.backend.mark_as_failure(self.task_id,
                                                  exc_info.exception)

        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,
                                        sys.getfilesystemencoding()),
                   "args": self.args,
                   "kwargs": self.kwargs}

        log_with_extra(self.logger, logging.ERROR,
                       self.error_msg.strip() % context,
                       exc_info=exc_info,
                       extra={"data": {"hostname": self.hostname,
                                       "id": self.task_id,
                                       "name": self.task_name}})

        task_obj = tasks.get(self.task_name, object)
        self.send_error_email(task_obj, context, exc_info.exception,
                              enabled=task_obj.send_error_emails,
                              whitelist=task_obj.error_whitelist)
Esempio n. 9
0
    def on_failure(self, exc_info):
        """The handler used if the task raised an exception."""
        from celery.conf import SEND_CELERY_TASK_ERROR_EMAILS

        context = {
            "hostname": socket.gethostname(),
            "id": self.task_id,
            "name": self.task_name,
            "exc": exc_info.exception,
            "traceback": exc_info.traceback,
            "args": self.args,
            "kwargs": self.kwargs,
        }
        self.logger.error(self.fail_msg.strip() % context)

        task_obj = tasks.get(self.task_name, object)
        send_error_email = SEND_CELERY_TASK_ERROR_EMAILS and 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)
Esempio n. 10
0
    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)
        self.send_error_email(task_obj, context, exc_info.exception,
                              whitelist=conf.CELERY_TASK_ERROR_WHITELIST,
                              enabled=conf.CELERY_SEND_TASK_ERROR_EMAILS)