How to use the kombu.utils.encoding.safe_repr function in kombu

To help you get started, we’ve selected a few kombu examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github celery / celery / celery / worker / consumer / consumer.py View on Github external
def on_decode_error(self, message, exc):
        """Callback called if an error occurs while decoding a message.

        Simply logs the error and acknowledges the message so it
        doesn't enter a loop.

        Arguments:
            message (kombu.Message): The message received.
            exc (Exception): The exception being handled.
        """
        crit(MESSAGE_DECODE_ERROR,
             exc, message.content_type, message.content_encoding,
             safe_repr(message.headers), dump_body(message, message.body),
             exc_info=1)
        message.ack()
github ansible / awx / awx / lib / site-packages / celery / worker / job.py View on Github external
def _log_error(self, einfo, send_failed_event=True):
        einfo.exception = get_pickled_exception(einfo.exception)
        eobj = einfo.exception
        exception, traceback, exc_info, internal, sargs, skwargs = (
            safe_repr(eobj),
            safe_str(einfo.traceback),
            einfo.exc_info,
            einfo.internal,
            safe_repr(self.args),
            safe_repr(self.kwargs),
        )
        task = self.task
        if task.throws and isinstance(eobj, task.throws):
            severity, exc_info = logging.INFO, None
            description = 'raised expected'
        else:
            severity = logging.ERROR
            description = 'raised unexpected'
        format = self.error_msg
        if send_failed_event:
            self.send_event(
                'task-failed', exception=exception, traceback=traceback,
            )

        if internal:
            if isinstance(einfo.exception, MemoryError):
github ansible / awx / awx / lib / site-packages / celery / worker / strategy.py View on Github external
req = Req(body, on_ack=ack, on_reject=reject,
                  app=app, hostname=hostname,
                  eventer=eventer, task=task,
                  connection_errors=connection_errors,
                  message=message)
        if req.revoked():
            return

        if _does_info:
            info('Received task: %s', req)

        if events:
            send_event(
                'task-received',
                uuid=req.id, name=req.name,
                args=safe_repr(req.args), kwargs=safe_repr(req.kwargs),
                retries=req.request_dict.get('retries', 0),
                eta=req.eta and req.eta.isoformat(),
                expires=req.expires and req.expires.isoformat(),
            )

        if req.eta:
            try:
                if req.utc:
                    eta = to_timestamp(to_system_tz(req.eta))
                else:
                    eta = to_timestamp(req.eta, timezone.local)
            except OverflowError as exc:
                error("Couldn't convert eta %s to timestamp: %r. Task: %r",
                      req.eta, exc, req.info(safe=True), exc_info=True)
                req.acknowledge()
            else:
github ansible / awx / awx / lib / site-packages / celery / worker / job.py View on Github external
def repr_result(self, result, maxlen=RESULT_MAXLEN):
        # 46 is the length needed to fit
        #     'the quick brown fox jumps over the lazy dog' :)
        if not isinstance(result, string_t):
            result = safe_repr(result)
        return truncate(result) if len(result) > maxlen else result
github ansible / awx / awx / lib / site-packages / celery / worker / job.py View on Github external
def info(self, safe=False):
        return {'id': self.id,
                'name': self.name,
                'args': self.args if safe else safe_repr(self.args),
                'kwargs': self.kwargs if safe else safe_repr(self.kwargs),
                'hostname': self.hostname,
                'time_start': self.time_start,
                'acknowledged': self.acknowledged,
                'delivery_info': self.delivery_info,
                'worker_pid': self.worker_pid}
github celery / cyme / cyme / api / web.py View on Github external
def dispatch(self, request, *args, **kwargs):
        self.nowait = kwargs.get('nowait', False)
        if request.method.lower() == 'get':
            kwargs.pop('nowait', None)
            if self.nowait:
                return self.NotImplemented('Operation cannot be async.')
        try:
            data = super(ApiView, self).dispatch(request, *args, **kwargs)
        except NoRouteError:
            return HttpResponseNotFound()
        except NoReplyError:
            return HttpResponseTimeout()
        except Exception, exc:
            return Error({'nok': [safe_repr(exc),
                                  ''.join(format_exception(*sys.exc_info()))]})
        return self.Response(data)
github celery / celery / celery / worker / job.py View on Github external
def _log_error(self, einfo):
        einfo.exception = get_pickled_exception(einfo.exception)
        exception, traceback, exc_info, internal, sargs, skwargs = (
            safe_repr(einfo.exception),
            safe_str(einfo.traceback),
            einfo.exc_info,
            einfo.internal,
            safe_repr(self.args),
            safe_repr(self.kwargs),
        )
        format = self.error_msg
        description = 'raised exception'
        severity = logging.ERROR
        self.send_event(
            'task-failed', exception=exception, traceback=traceback,
        )

        if internal:
            if isinstance(einfo.exception, Ignore):
                format = self.ignored_msg
github celery / celery / celery / worker / consumer / consumer.py View on Github external
def _message_report(self, body, message):
        return MESSAGE_REPORT.format(dump_body(message, body),
                                     safe_repr(message.content_type),
                                     safe_repr(message.content_encoding),
                                     safe_repr(message.delivery_info),
                                     safe_repr(message.headers))
github celery / kombu / kombu / utils / functional.py View on Github external
def reprkwargs(kwargs, sep=', ', fmt='{0}={1}'):
    return sep.join(fmt.format(k, _safe_repr(v)) for k, v in items(kwargs))
github ansible / awx / awx / lib / site-packages / celery / worker / job.py View on Github external
def info(self, safe=False):
        return {'id': self.id,
                'name': self.name,
                'args': self.args if safe else safe_repr(self.args),
                'kwargs': self.kwargs if safe else safe_repr(self.kwargs),
                'hostname': self.hostname,
                'time_start': self.time_start,
                'acknowledged': self.acknowledged,
                'delivery_info': self.delivery_info,
                'worker_pid': self.worker_pid}