Beispiel #1
0
    def handle_failure(self, task, req, store_errors=True, call_errbacks=True):
        """Handle exception."""
        _, _, tb = sys.exc_info()
        try:
            exc = self.retval
            # make sure we only send pickleable exceptions back to parent.
            einfo = ExceptionInfo()
            einfo.exception = get_pickleable_exception(einfo.exception)
            einfo.type = get_pickleable_etype(einfo.type)

            task.backend.mark_as_failure(
                req.id, exc, einfo.traceback,
                request=req, store_result=store_errors,
                call_errbacks=call_errbacks,
            )

            task.on_failure(exc, req.id, req.args, req.kwargs, einfo)
            signals.task_failure.send(sender=task, task_id=req.id,
                                      exception=exc, args=req.args,
                                      kwargs=req.kwargs,
                                      traceback=tb,
                                      einfo=einfo)
            self._log_error(task, req, einfo)
            return einfo
        finally:
            del(tb)
Beispiel #2
0
    def handle_failure(self, task, req, store_errors=True, call_errbacks=True):
        """Handle exception."""
        _, _, tb = sys.exc_info()
        try:
            exc = self.retval
            # make sure we only send pickleable exceptions back to parent.
            einfo = ExceptionInfo()
            einfo.exception = get_pickleable_exception(einfo.exception)
            einfo.type = get_pickleable_etype(einfo.type)

            task.backend.mark_as_failure(
                req.id, exc, einfo.traceback,
                request=req, store_result=store_errors,
                call_errbacks=call_errbacks,
            )

            task.on_failure(exc, req.id, req.args, req.kwargs, einfo)
            signals.task_failure.send(sender=task, task_id=req.id,
                                      exception=exc, args=req.args,
                                      kwargs=req.kwargs,
                                      traceback=tb,
                                      einfo=einfo)
            self._log_error(task, req, einfo)
            return einfo
        finally:
            del tb
Beispiel #3
0
 def handle_failure(self, task, store_errors=True):
     """Handle exception."""
     req = task.request
     type_, _, tb = sys.exc_info()
     try:
         exc = self.retval
         einfo = ExceptionInfo()
         einfo.exception = get_pickleable_exception(einfo.exception)
         einfo.type = get_pickleable_etype(einfo.type)
         if store_errors:
             task.backend.mark_as_failure(
                 req.id,
                 exc,
                 einfo.traceback,
                 request=req,
             )
         task.on_failure(exc, req.id, req.args, req.kwargs, einfo)
         signals.task_failure.send(sender=task,
                                   task_id=req.id,
                                   exception=exc,
                                   args=req.args,
                                   kwargs=req.kwargs,
                                   traceback=tb,
                                   einfo=einfo)
         return einfo
     finally:
         del (tb)
Beispiel #4
0
 def prepare_exception(self, exc, serializer=None):
     """Prepare exception for serialization."""
     serializer = self.serializer if serializer is None else serializer
     if serializer in EXCEPTION_ABLE_CODECS:
         return get_pickleable_exception(exc)
     return {'exc_type': type(exc).__name__,
             'exc_message': exc.args,
             'exc_module': type(exc).__module__}
Beispiel #5
0
 def prepare_exception(self, exc):
     """Prepare exception for serialization."""
     if (self.app.conf["CELERY_RESULT_SERIALIZER"] in ("pickle", "yaml")):
         return get_pickleable_exception(exc)
     return {
         "exc_type": type(exc).__name__,
         "exc_message": str(exc),
     }
Beispiel #6
0
 def prepare_exception(self, exc, serializer=None):
     """Prepare exception for serialization."""
     serializer = self.serializer if serializer is None else serializer
     if serializer in EXCEPTION_ABLE_CODECS:
         return get_pickleable_exception(exc)
     exctype = type(exc)
     return {'exc_type': getattr(exctype, '__qualname__', exctype.__name__),
             'exc_message': ensure_serializable(exc.args, self.encode),
             'exc_module': exctype.__module__}
Beispiel #7
0
 def handle_failure(self, task, store_errors=True):
     """Handle exception."""
     req = task.request
     exc, type_, tb = self.retval, self.exc_type, self.tb
     if store_errors:
         task.backend.mark_as_failure(req.id, exc, self.strtb)
     exc = get_pickleable_exception(exc)
     einfo = ExceptionInfo((type_, exc, tb))
     task.on_failure(exc, req.id, req.args, req.kwargs, einfo)
     signals.task_failure.send(sender=task, task_id=req.id,
                               exception=exc, args=req.args,
                               kwargs=req.kwargs, traceback=tb,
                               einfo=einfo)
     return einfo
Beispiel #8
0
 def handle_failure(self, task, store_errors=True):
     """Handle exception."""
     req = task.request
     exc, type_, tb = self.retval, self.exc_type, self.tb
     if store_errors:
         task.backend.mark_as_failure(req.id, exc, self.strtb)
     exc = get_pickleable_exception(exc)
     einfo = ExceptionInfo((type_, exc, tb))
     task.on_failure(exc, req.id, req.args, req.kwargs, einfo)
     signals.task_failure.send(sender=task,
                               task_id=req.id,
                               exception=exc,
                               args=req.args,
                               kwargs=req.kwargs,
                               traceback=tb,
                               einfo=einfo)
     return einfo
Beispiel #9
0
 def handle_failure(self, task, store_errors=True):
     """Handle exception."""
     req = task.request
     type_, _, tb = sys.exc_info()
     try:
         exc = self.retval
         einfo = ExceptionInfo((type_, get_pickleable_exception(exc), tb))
         if store_errors:
             task.backend.mark_as_failure(req.id, exc, einfo.traceback)
         task.on_failure(exc, req.id, req.args, req.kwargs, einfo)
         signals.task_failure.send(sender=task, task_id=req.id,
                                   exception=exc, args=req.args,
                                   kwargs=req.kwargs,
                                   traceback=einfo.tb,
                                   einfo=einfo)
         return einfo
     finally:
         del(tb)
Beispiel #10
0
    def on_success(self, retval, task_id, args, kwargs):
        try:
            logger.info(
                'my task success and taskid is {} ,retval is{} ,args is{}.kwargs id {}'
                .format(task_id, retval, args, kwargs))
            # 如果执行成功,且有下一步,则执行下一步
            if self.do_success(retval, task_id, args,
                               kwargs) and kwargs.get('next_task_kwargs'):
                for next_task_kwarg in kwargs['next_task_kwargs']:
                    with session_scope() as ss:
                        from worker.run_task import run_celery_task
                        run_celery_task(session=ss, **next_task_kwarg)

        except Exception as e:
            einfo = ExceptionInfo()
            einfo.exception = get_pickleable_exception(einfo.exception)
            einfo.type = get_pickleable_etype(einfo.type)
            self.on_failure(e, task_id, args, kwargs, einfo)
Beispiel #11
0
def _signal_internal_error(task, uuid, args, kwargs, request, exc):
    """Send a special `internal_error` signal to the app for outside body errors."""
    try:
        _, _, tb = sys.exc_info()
        einfo = ExceptionInfo()
        einfo.exception = get_pickleable_exception(einfo.exception)
        einfo.type = get_pickleable_etype(einfo.type)
        signals.task_internal_error.send(
            sender=task,
            task_id=uuid,
            args=args,
            kwargs=kwargs,
            request=request,
            exception=exc,
            traceback=tb,
            einfo=einfo,
        )
    finally:
        del tb
Beispiel #12
0
 def prepare_exception(self, exc):
     """Prepare exception for serialization."""
     if self.serializer in EXCEPTION_ABLE_CODECS:
         return get_pickleable_exception(exc)
     return {'exc_type': type(exc).__name__, 'exc_message': str(exc)}
Beispiel #13
0
 def prepare_exception(self, exc):
     """Prepare exception for serialization."""
     if app_or_default().conf["CELERY_RESULT_SERIALIZER"] in ("pickle", "yaml"):
         return get_pickleable_exception(exc)
     return {"exc_type": type(exc).__name__, "exc_message": str(exc)}
Beispiel #14
0
 def prepare_exception(self, exc):
     """Prepare exception for serialization."""
     if self.serializer in EXCEPTION_ABLE_CODECS:
         return get_pickleable_exception(exc)
     return {'exc_type': type(exc).__name__, 'exc_message': str(exc)}
Beispiel #15
0
 def prepare_exception(self, exc, serializer=None):
     """Prepare exception for serialization."""
     serializer = self.serializer if serializer is None else serializer
     if serializer in EXCEPTION_ABLE_CODECS:
         return get_pickleable_exception(exc)
     return {"exc_type": type(exc).__name__, "exc_message": str(exc)}
Beispiel #16
0
 def prepare_exception(self, exc):
     """Prepare exception for serialization."""
     return get_pickleable_exception(exc)
Beispiel #17
0
 def prepare_exception(self, exc):
     """Prepare exception for serialization."""
     return get_pickleable_exception(exc)