Exemple #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

        @current_app.task
        def xtask():
            pass

        trace_task(xtask, 'uuid', (), {})
        self.assertTrue(report_internal_error.call_count)
        self.assertIs(xtask.__trace__, tracer)
Exemple #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

        @current_app.task
        def xtask():
            pass

        trace_task(xtask, "uuid", (), {})
        self.assertTrue(report_internal_error.call_count)
        self.assertIs(xtask.__tracer__, tracer)
Exemple #3
0
    def execute(self, loglevel=None, logfile=None):
        """Execute the task in a :func:`~celery.task.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
Exemple #4
0
    def execute(self, loglevel=None, logfile=None):
        """Execute the task in a :func:`~celery.task.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
Exemple #5
0
def jail(task_id, name, args, kwargs):
    request = {'id': task_id}
    task = current_app.tasks[name]
    task.__trace__ = None  # rebuild
    return trace_task(
        task, task_id, args, kwargs, request=request, eager=False,
    )
Exemple #6
0
def jail(task_id, name, args, kwargs):
    request = {'id': task_id}
    task = current_app.tasks[name]
    task.__trace__ = None  # rebuild
    return trace_task(
        task, task_id, args, kwargs, request=request, eager=False,
    )
Exemple #7
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)
Exemple #8
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)