Exemplo n.º 1
0
    def test_schedule_node_exec_uses_task_options(self):
        wf = Workflow()
        task_cls = mock.Mock()
        signature = mock.Mock()
        node = mock.Mock()
        node.id = 'task_node'
        task_cls.subtask.return_value = signature
        signature.id = 'dummy'
        Workflow.set_workflow_processor_task(task_cls)

        options = {'option': True}
        wf.apply_async(options=options)
        wf.schedule_node_exec(node)

        signature.apply_async.assert_called_with()
        node.signature.apply_async.assert_called_with(**options)
Exemplo n.º 2
0
def register_workflow_processor(app, **decorator_kws):
    """
    Attach workflow tasks to given celery app instance
    """
    decorator_defaults = dict(
        name='workflow-processor',
        bind=True,
        max_retries=1,
    )
    if decorator_kws is not None:
        decorator_defaults.update(decorator_kws)

    task = app.task(**decorator_defaults)(workflow_processor)

    Workflow.set_workflow_processor_task(task)
    return task
Exemplo n.º 3
0
    def test_apply_async(self):
        wf = Workflow()
        task_cls = mock.Mock()
        signature = mock.Mock()
        task_cls.subtask.return_value = signature
        signature.id = 'dummy'
        Workflow.set_workflow_processor_task(task_cls)

        wf.apply_async()
        assert wf.id == 'dummy'

        # trickery, task_cls.subtask was called before ID was assigned
        # to workflow, while now wf.to_dict has id field set
        # just set it back to None
        wf.id = None
        task_cls.subtask.assert_called_with(kwargs=dict(
            workflow_dict=wf.to_dict()))
        signature.apply_async.assert_called()
Exemplo n.º 4
0
 def test_freeze_no_task(self):
     wf = Workflow()
     wf.set_workflow_processor_task(None)
     with pytest.raises(WorkflowException, match="task is not set"):
         wf.freeze()