Esempio n. 1
0
    def test_tpc_finish_multiple(t, _transaction, _stage, _commit):
        sig1 = Signature("mock.task", args=(10,), options={"task_id": "1"})
        sig2 = Signature("mock.task", args=(11,), options={"task_id": "2"})
        apply1 = Mock()
        sig1.apply_async = apply1
        apply2 = Mock()
        sig2.apply_async = apply2
        tx = Mock()

        t.dispatcher.add(sig1)
        t.dispatcher.add(sig2)

        t.dispatcher.tpc_finish(tx)
        t.assertTupleEqual((), t.dispatcher.staged)
        t.assertListEqual([], t.dispatcher._signatures)
        t.storage.mdelete.assert_not_called()
        apply1.assert_called_once_with()
        apply2.assert_called_once_with()
        calls = [call(t.storage, sig1), call(t.storage, sig2)]
        _commit.assert_has_calls(calls)
Esempio n. 2
0
 def __call__(self, *args: Any, **kwargs: Any) -> str:
     self.func(*args, **kwargs)
     s = Signature(
         args=args,
         kwargs=kwargs,
         task=self.name,
         app=self.app,
         task_type=self.app.Task,
         routing_key=self.name)
     result: AsyncResult = s.apply_async()
     return result.id
Esempio n. 3
0
 def test_tpc_finish(t, _transaction, _stage, _commit):
     sig = Signature("mock.task", args=(10,), options={"task_id": "1"})
     apply_mock = Mock()
     sig.apply_async = apply_mock
     tx = Mock()
     t.dispatcher.add(sig)
     t.dispatcher.tpc_finish(tx)
     t.assertTupleEqual((), t.dispatcher.staged)
     t.assertListEqual([], t.dispatcher._signatures)
     t.storage.mdelete.assert_not_called()
     apply_mock.assert_called_once_with()
     _commit.assert_called_once_with(t.storage, sig)
Esempio n. 4
0
    def apply_async(self, args=(), kwargs={}, route_name=None, **options):
        """Apply this task asynchronously.

        :param tuple args: Partial args to be prepended to the existing args.
        :param dict kwargs : Partial kwargs to be merged with existing kwargs.
        :param dict options: Partial options to be merged with existing options.

        :return: ~@AsyncResult: promise of future evaluation.

        See also:
            :meth:`[email protected]_async` and the :ref:`guide-calling` guide.
        """
        taskid = CelerySignature.apply_async(self, args, kwargs, route_name,
                                             **options)
        logger.debug('Create new task: %s' % taskid)
        return taskid
Esempio n. 5
0
    def apply_async(self, args=(), kwargs={}, route_name=None, **options):
        """Apply this task asynchronously.

        Arguments:
            args (Tuple): Partial args to be prepended to the existing args.
            kwargs (Dict): Partial kwargs to be merged with existing kwargs.
            options (Dict): Partial options to be merged
                with existing options.

        Returns:
            ~@AsyncResult: promise of future evaluation.

        See also:
            :meth:`[email protected]_async` and the :ref:`guide-calling` guide.
        """
        jobid = CelerySignature.apply_async(self, args, kwargs, route_name,
                                            **options)
        task = TaskResult.task_pending(str(jobid))
        logger.debug('Create new task: %s' % task)
        return jobid
Esempio n. 6
0
def update_analysis(analysis_id):
    """ Launches async job to update analysis """
    task = Signature("analysis.tasks.analysis_update_tasks.create_and_launch_analysis_tasks", args=(analysis_id,))
    task.apply_async()