예제 #1
0
    def test_outside_body_error(self, report_internal_error, build_tracer):
        tracer = Mock()
        tracer.side_effect = KeyError('foo')
        build_tracer.return_value = tracer

        @self.app.task(shared=False)
        def xtask():
            pass

        trace_task(xtask, 'uuid', (), {})
        self.assertTrue(report_internal_error.call_count)
        self.assertIs(xtask.__trace__, tracer)
예제 #2
0
    def test_outside_body_error(self, report_internal_error, build_tracer):
        tracer = Mock()
        tracer.side_effect = KeyError('foo')
        build_tracer.return_value = tracer

        @self.app.task(shared=False)
        def xtask():
            pass

        trace_task(xtask, 'uuid', (), {})
        self.assertTrue(report_internal_error.call_count)
        self.assertIs(xtask.__trace__, tracer)
예제 #3
0
    def execute(self, loglevel=None, logfile=None):
        """Execute the task in a :func:`~celery.app.trace.trace_task`.

        Arguments:
            loglevel (int): The loglevel used by the task.
            logfile (str): The logfile used by the task.
        """
        if self.revoked():
            return

        # acknowledge task as being processed.
        if not self.task.acks_late:
            self.acknowledge()

        request = self.request_dict
        # pylint: disable=unpacking-non-sequence
        #    payload is a property, so pylint doesn't think it's a tuple.
        args, kwargs, embed = self._payload
        request.update({
            'loglevel': loglevel,
            'logfile': logfile,
            'hostname': self.hostname,
            'is_eager': False,
            'args': args,
            'kwargs': kwargs
        }, **embed or {})
        retval = trace_task(self.task, self.id, args, kwargs, request,
                            hostname=self.hostname, loader=self.app.loader,
                            app=self.app)[0]
        self.acknowledge()
        return retval
예제 #4
0
파일: request.py 프로젝트: eliziario/celery
    def execute(self, loglevel=None, logfile=None):
        """Execute the task in a :func:`~celery.app.trace.trace_task`.

        :keyword loglevel: The loglevel used by the task.
        :keyword logfile: The logfile used by the task.

        """
        if self.revoked():
            return

        # acknowledge task as being processed.
        if not self.task.acks_late:
            self.acknowledge()

        request = self.request_dict
        args, kwargs, embed = self._payload
        request.update(
            {
                "loglevel": loglevel,
                "logfile": logfile,
                "hostname": self.hostname,
                "is_eager": False,
                "args": args,
                "kwargs": kwargs,
            },
            **embed or {}
        )
        retval = trace_task(
            self.task, self.id, args, kwargs, request, hostname=self.hostname, loader=self.app.loader, app=self.app
        )[0]
        self.acknowledge()
        return retval
예제 #5
0
def jail(app, task_id, name, args, kwargs):
    request = {'id': task_id}
    task = app.tasks[name]
    task.__trace__ = None  # rebuild
    return trace_task(
        task, task_id, args, kwargs, request=request, eager=False, app=app,
    ).retval
예제 #6
0
def jail(app, task_id, name, args, kwargs):
    request = {'id': task_id}
    task = app.tasks[name]
    task.__trace__ = None  # rebuild
    return trace_task(
        task, task_id, args, kwargs, request=request, eager=False, app=app,
    ).retval
예제 #7
0
파일: request.py 프로젝트: jdufresne/celery
    def execute(self, loglevel=None, logfile=None):
        """Execute the task in a :func:`~celery.app.trace.trace_task`.

        Arguments:
            loglevel (int): The loglevel used by the task.
            logfile (str): The logfile used by the task.
        """
        if self.revoked():
            return

        # acknowledge task as being processed.
        if not self.task.acks_late:
            self.acknowledge()

        request = self.request_dict
        # pylint: disable=unpacking-non-sequence
        #    payload is a property, so pylint doesn't think it's a tuple.
        args, kwargs, embed = self._payload
        request.update({
            'loglevel': loglevel,
            'logfile': logfile,
            'hostname': self.hostname,
            'is_eager': False,
            'args': args,
            'kwargs': kwargs
        }, **embed or {})
        retval = trace_task(self.task, self.id, args, kwargs, request,
                            hostname=self.hostname, loader=self.app.loader,
                            app=self.app)[0]
        self.acknowledge()
        return retval
예제 #8
0
파일: job.py 프로젝트: sysras0000/panop
    def execute(self, loglevel=None, logfile=None):
        """Execute the task in a :func:`~celery.app.trace.trace_task`.

        :keyword loglevel: The loglevel used by the task.
        :keyword logfile: The logfile used by the task.

        """
        if self.revoked():
            return

        # acknowledge task as being processed.
        if not self.task.acks_late:
            self.acknowledge()

        kwargs = self.kwargs
        if self.task.accept_magic_kwargs:
            kwargs = self.extend_with_default_kwargs()
        request = self.request_dict
        request.update({
            'loglevel': loglevel,
            'logfile': logfile,
            'hostname': self.hostname,
            'is_eager': False,
            'delivery_info': self.delivery_info
        })
        retval = trace_task(self.task,
                            self.id,
                            self.args,
                            kwargs,
                            request,
                            hostname=self.hostname,
                            loader=self.app.loader,
                            app=self.app)
        self.acknowledge()
        return retval
예제 #9
0
    def execute(self, loglevel=None, logfile=None):
        """Execute the task in a :func:`~celery.app.trace.trace_task`.

        :keyword loglevel: The loglevel used by the task.
        :keyword logfile: The logfile used by the task.

        """
        if self.revoked():
            return

        # acknowledge task as being processed.
        if not self.task.acks_late:
            self.acknowledge()

        request = self.request_dict
        args, kwargs, embed = self._payload
        request.update(
            {
                'loglevel': loglevel,
                'logfile': logfile,
                'hostname': self.hostname,
                'is_eager': False,
                'args': args,
                'kwargs': kwargs
            }, **embed or {})
        retval = trace_task(self.task,
                            self.id,
                            args,
                            kwargs,
                            request,
                            hostname=self.hostname,
                            loader=self.app.loader,
                            app=self.app)[0]
        self.acknowledge()
        return retval
예제 #10
0
파일: job.py 프로젝트: subssn21/celery
    def execute(self, loglevel=None, logfile=None):
        """Execute the task in a :func:`~celery.app.trace.trace_task`.

        :keyword loglevel: The loglevel used by the task.
        :keyword logfile: The logfile used by the task.

        """
        if self.revoked():
            return

        # acknowledge task as being processed.
        if not self.task.acks_late:
            self.acknowledge()

        kwargs = self.kwargs
        if self.task.accept_magic_kwargs:
            kwargs = self.extend_with_default_kwargs()
        request = self.request_dict
        request.update({'loglevel': loglevel, 'logfile': logfile,
                        'hostname': self.hostname, 'is_eager': False,
                        'delivery_info': self.delivery_info})
        retval = trace_task(self.task, self.id, self.args, kwargs, request,
                            **{'hostname': self.hostname,
                               'loader': self.app.loader})
        self.acknowledge()
        return retval
예제 #11
0
    def test_trace_catches_exception(self):
        @self.app.task(request=None, shared=False)
        def raising():
            raise KeyError('baz')

        with pytest.warns(RuntimeWarning):
            res = trace_task(raising, uuid(), [], {}, app=self.app)[0]
            assert isinstance(res, ExceptionInfo)
예제 #12
0
    def test_trace_catches_exception(self):

        @self.app.task(request=None, shared=False)
        def raising():
            raise KeyError('baz')

        with pytest.warns(RuntimeWarning):
            res = trace_task(raising, uuid(), [], {}, app=self.app)[0]
            assert isinstance(res, ExceptionInfo)
예제 #13
0
    def test_trace_catches_exception(self):
        @self.app.task(request=None, shared=False)
        def raising():
            raise KeyError('baz')

        with self.assertWarnsRegex(RuntimeWarning,
                                   r'Exception raised outside'):
            res = trace_task(raising, uuid(), [], {}, app=self.app)[0]
            self.assertIsInstance(res, ExceptionInfo)
예제 #14
0
    def test_trace_catches_exception(self):

        @self.app.task(request=None, shared=False)
        def raising():
            raise KeyError('baz')

        with self.assertWarnsRegex(RuntimeWarning,
                                   r'Exception raised outside'):
            res = trace_task(raising, uuid(), [], {}, app=self.app)[0]
            self.assertIsInstance(res, ExceptionInfo)
예제 #15
0
    def test_trace_catches_exception(self):
        def _error_exec(self, *args, **kwargs):
            raise KeyError("baz")

        @self.app.task(request=None, shared=False)
        def raising():
            raise KeyError("baz")

        with self.assertWarnsRegex(RuntimeWarning, r"Exception raised outside"):
            res = trace_task(raising, uuid(), [], {}, app=self.app)
            self.assertIsInstance(res, ExceptionInfo)
예제 #16
0
    def test_execute_safe_catches_exception(self):
        def _error_exec(self, *args, **kwargs):
            raise KeyError('baz')

        @task_dec(request=None)
        def raising():
            raise KeyError('baz')

        with self.assertWarnsRegex(RuntimeWarning,
                                   r'Exception raised outside'):
            res = trace_task(raising, uuid(), [], {})
            self.assertIsInstance(res, ExceptionInfo)
예제 #17
0
    def test_execute_safe_catches_exception(self):

        def _error_exec(self, *args, **kwargs):
            raise KeyError('baz')

        @task_dec(request=None)
        def raising():
            raise KeyError('baz')

        with self.assertWarnsRegex(
                RuntimeWarning, r'Exception raised outside'):
            res = trace_task(raising, uuid(), [], {})
            self.assertIsInstance(res, ExceptionInfo)
예제 #18
0
        def wrapper(*args, **kwargs):
            # This must be a string, or else we'll get an
            # AttributeError.
            task_id = text_type(uuid4())

            # Based on a template found in Celery unit tests.
            # :py:func:`celery.tests.case.body_from_sig`
            request = {
                'id': task_id,
                'retries': task_instance.depth,
                'task': task.name,

                # These will be set later.
                'args': (),
                'kwargs': {},

                #
                # :py:class:`ThreadingTaskRunner` does not respect
                # cooldown.
                #
                # At some point, we might change this, but for now, the
                # only time we use :py:class:`ThreadingTaskRunner` is
                # in unit tests where cooldown would be very annoying.
                #
                'eta': None,

                # These attributes should remain empty, to match the
                # behavior of CeleryTaskRunner.
                'callbacks': [],
                'errbacks': [],
                'utc': None,
                'expires': None,
            }

            try:
                # :py:func:`trace_task` ensures that handlers get
                # executed correctly.
                return trace_task(
                    task=task,
                    uuid=task_id,
                    args=args,
                    kwargs=kwargs,
                    request=request,
                    app=current_app,
                )
            finally:
                task.cleanup_thread()
예제 #19
0
    def test_backend_error_should_report_failure(self):
        """check internal error is reported as failure.

        In case of backend error, an exception may bubble up from trace and be
        caught by trace_task.
        """
        @self.app.task(shared=False)
        def xtask():
            pass

        xtask.backend = BaseDictBackend(app=self.app)
        xtask.backend.mark_as_done = Mock()
        xtask.backend.mark_as_done.side_effect = Exception()
        xtask.backend.mark_as_failure = Mock()
        xtask.backend.mark_as_failure.side_effect = Exception()

        ret, info, _, _ = trace_task(xtask, 'uuid', (), {}, app=self.app)
        assert info is not None
        assert isinstance(ret, ExceptionInfo)
예제 #20
0
    def execute(self, loglevel=None, logfile=None):
        """Execute the task in a :func:`~celery.app.trace.trace_task`.

        Arguments:
            loglevel (int): The loglevel used by the task.
            logfile (str): The logfile used by the task.
        """
        if self.revoked():
            return

        # acknowledge task as being processed.
        if not self.task.acks_late:
            self.acknowledge()

        _, _, embed = self._payload
        request = self._request_dict
        # pylint: disable=unpacking-non-sequence
        #    payload is a property, so pylint doesn't think it's a tuple.
        request.update(
            {
                "loglevel": loglevel,
                "logfile": logfile,
                "is_eager": False,
            }, **embed or {})

        retval, I, _, _ = trace_task(
            self.task,
            self.id,
            self._args,
            self._kwargs,
            request,
            hostname=self._hostname,
            loader=self._app.loader,
            app=self._app,
        )

        if I:
            self.reject(requeue=False)
        else:
            self.acknowledge()
        return retval
예제 #21
0
    def execute(self, loglevel=None, logfile=None):
        """Execute the task in a :func:`~celery.app.trace.trace_task`.

        :keyword loglevel: The loglevel used by the task.
        :keyword logfile: The logfile used by the task.

        """
        if self.revoked():
            return

        # acknowledge task as being processed.
        if not self.task.acks_late:
            self.acknowledge()

        request = self.request_dict
        args, kwargs = self.message.payload
        request.update({'loglevel': loglevel, 'logfile': logfile,
                        'hostname': self.hostname, 'is_eager': False,
                        'args': args, 'kwargs': kwargs})
        retval = trace_task(self.task, self.id, args, kwargs, request,
                            hostname=self.hostname, loader=self.app.loader,
                            app=self.app)[0]
        self.acknowledge()
        return retval