예제 #1
0
    def test_apply_async(self):

        applied = [0]

        class mocksubtask(Signature):

            def apply_async(self, *args, **kwargs):
                applied[0] += 1

        ts = TaskSet([mocksubtask(MockTask, (i, i))
                        for i in (2, 4, 8)])
        ts.apply_async()
        self.assertEqual(applied[0], 3)

        class Publisher(object):

            def send(self, *args, **kwargs):
                pass

        ts.apply_async(publisher=Publisher())

        # setting current_task

        @current_app.task
        def xyz():
            pass
        from celery.state import _task_stack
        _task_stack.push(xyz)
        try:
            ts.apply_async(publisher=Publisher())
        finally:
            _task_stack.pop()
            xyz.pop_request()
예제 #2
0
파일: task.py 프로젝트: AdrianRibao/celery
 def __call__(self, *args, **kwargs):
     _task_stack.push(self)
     self.push_request()
     try:
         return self.run(*args, **kwargs)
     finally:
         self.pop_request()
         _task_stack.pop()
예제 #3
0
 def __call__(self, *args, **kwargs):
     _task_stack.push(self)
     self.push_request()
     try:
         return self.run(*args, **kwargs)
     finally:
         self.pop_request()
         _task_stack.pop()
예제 #4
0
 def test_apply_async_with_parent(self):
     _task_stack.push(add)
     try:
         x = group([add.s(4, 4), add.s(8, 8)])
         x.apply_async()
         self.assertTrue(add.request.children)
     finally:
         _task_stack.pop()
예제 #5
0
 def test_apply_async_with_parent(self):
     _task_stack.push(add)
     try:
         add.push_request(called_directly=False)
         try:
             assert not add.request.children
             x = group([add.s(4, 4), add.s(8, 8)])
             res = x()
             self.assertTrue(add.request.children)
             self.assertIn(res, add.request.children)
             self.assertEqual(len(add.request.children), 1)
         finally:
             add.pop_request()
     finally:
         _task_stack.pop()
예제 #6
0
 def test_apply_async_with_parent(self):
     _task_stack.push(add)
     try:
         add.push_request(called_directly=False)
         try:
             assert not add.request.children
             x = group([add.s(4, 4), add.s(8, 8)])
             res = x()
             self.assertTrue(add.request.children)
             self.assertIn(res, add.request.children)
             self.assertEqual(len(add.request.children), 1)
         finally:
             add.pop_request()
     finally:
         _task_stack.pop()
예제 #7
0
    def test_apply_async_adds_children(self):
        from celery.state import _task_stack
        app = Celery(set_as_current=False)

        @app.task()
        def a3cX1(self):
            pass

        @app.task()
        def a3cX2(self):
            pass

        _task_stack.push(a3cX1)
        try:
            a3cX1.push_request(called_directly=False)
            try:
                res = a3cX2.apply_async(add_to_parent=True)
                self.assertIn(res, a3cX1.request.children)
            finally:
                a3cX1.pop_request()
        finally:
            _task_stack.pop()
예제 #8
0
    def test_apply_async_adds_children(self):
        from celery.state import _task_stack
        app = Celery(set_as_current=False)

        @app.task()
        def a3cX1(self):
            pass

        @app.task()
        def a3cX2(self):
            pass

        _task_stack.push(a3cX1)
        try:
            a3cX1.push_request(called_directly=False)
            try:
                res = a3cX2.apply_async(add_to_parent=True)
                self.assertIn(res, a3cX1.request.children)
            finally:
                a3cX1.pop_request()
        finally:
            _task_stack.pop()
예제 #9
0
파일: trace.py 프로젝트: errord/celery
                    if task_on_success:
                        task_on_success(retval, uuid, args, kwargs)
                    if success_receivers:
                        send_success(sender=task, result=retval)

                # -* POST *-
                if task_request.chord:
                    on_chord_part_return(task)
                if task_after_return:
                    task_after_return(state, retval, uuid, args, kwargs, None)
                if postrun_receivers:
                    send_postrun(sender=task, task_id=uuid, task=task,
                                 args=args, kwargs=kwargs,
                                 retval=retval, state=state)
            finally:
                _task_stack.pop()
                pop_request()
                if not eager:
                    try:
                        backend_cleanup()
                        loader_cleanup()
                    except (KeyboardInterrupt, SystemExit, MemoryError):
                        raise
                    except Exception, exc:
                        _logger.error("Process cleanup failed: %r", exc,
                                      exc_info=True)
        except Exception, exc:
            if eager:
                raise
            R = report_internal_error(task, exc)
        return R, I
예제 #10
0
 def tearDown(self):
     from celery.state import _task_stack
     _task_stack.pop()
예제 #11
0
파일: test_log.py 프로젝트: ahalife/celery
 def tearDown(self):
     from celery.state import _task_stack
     _task_stack.pop()