示例#1
0
def test_eq() -> None:
    s1 = Step("a", PerformAction("a"), timedelta())
    s2 = Step("a", WaitForEvent("a", {"foo": "bla"}), timedelta())
    s3 = Step("a", EmitEvent(Event("a", {"a": "b"})), timedelta())
    s4 = Step("a", ExecuteCommand("echo hello"), timedelta())
    assert s1 == Step("a", PerformAction("a"), timedelta())
    assert s2 == Step("a", WaitForEvent("a", {"foo": "bla"}), timedelta())
    assert s3 == Step("a", EmitEvent(Event("a", {"a": "b"})), timedelta())
    assert s4 == Step("a", ExecuteCommand("echo hello"), timedelta())
    trigger = [EventTrigger("start me up")]
    assert Workflow("a", "a", [s1, s2, s3, s4],
                    trigger) == Workflow("a", "a", [s1, s2, s3, s4], trigger)
示例#2
0
async def test_wait_for_running_job(
    task_handler: TaskHandlerService, test_workflow: Workflow, all_events: List[Message]
) -> None:
    test_workflow.on_surpass = TaskSurpassBehaviour.Wait
    task_handler.task_descriptions = [test_workflow]
    # subscribe as collect handler - the workflow will need to wait for this handler
    sub = await task_handler.subscription_handler.add_subscription(
        SubscriberId("sub_1"), "collect", True, timedelta(seconds=30)
    )
    await task_handler.handle_event(Event("start me up"))
    # check, that the workflow has started
    running_before = await task_handler.running_tasks()
    assert len(running_before) == 1
    act: Action = await wait_for_message(all_events, "collect", Action)
    # pull the same trigger: the workflow can not be started, since there is already one in progress -> wait
    await task_handler.handle_event(Event("start me up"))
    # report success of the only subscriber
    await task_handler.handle_action_done(ActionDone("collect", act.task_id, act.step_name, sub.id, dict(act.data)))
    # check overdue tasks: wipe finished tasks and eventually start waiting tasks
    await task_handler.check_overdue_tasks()
    # check, that the workflow has started
    running_after = await task_handler.running_tasks()
    assert len(running_after) == 1
    t_before, t_after = running_before[0], running_after[0]
    assert t_before.descriptor.id == t_after.descriptor.id and t_before.id != t_after.id
示例#3
0
def test_workflow() -> Workflow:
    return Workflow(
        TaskDescriptorId("test_workflow"),
        "Speakable name of workflow",
        [
            Step("start", PerformAction("start_collect"), timedelta(seconds=10)),
            Step("act", PerformAction("collect"), timedelta(seconds=10)),
            Step("done", PerformAction("collect_done"), timedelta(seconds=10), StepErrorBehaviour.Stop),
        ],
        [EventTrigger("start me up"), TimeTrigger("1 1 1 1 1")],
    )
def test_workflow() -> Workflow:
    return Workflow(
        TaskDescriptorId("test_workflow"),
        "Speakable name of workflow",
        [
            Step("start", PerformAction("start_collect"), timedelta(seconds=10)),
            Step("wait", WaitForEvent("godot", {"a": 1}), timedelta(seconds=10)),
            Step("emit_event", EmitEvent(Event("hello", {"a": 1})), timedelta(seconds=10)),
            Step("collect", PerformAction("collect"), timedelta(seconds=10)),
            Step("done", PerformAction("collect_done"), timedelta(seconds=10), StepErrorBehaviour.Stop),
        ],
        [EventTrigger("start me up")],
    )
示例#5
0
 def known_workflows() -> List[Workflow]:
     collect_steps = [
         Step("pre_collect", PerformAction("pre_collect"),
              timedelta(seconds=10)),
         Step("collect", PerformAction("collect"), timedelta(seconds=10)),
         Step("post_collect", PerformAction("post_collect"),
              timedelta(seconds=10)),
     ]
     cleanup_steps = [
         Step("pre_cleanup_plan", PerformAction("pre_cleanup_plan"),
              timedelta(seconds=10)),
         Step("cleanup_plan", PerformAction("cleanup_plan"),
              timedelta(seconds=10)),
         Step("post_cleanup_plan", PerformAction("post_cleanup_plan"),
              timedelta(seconds=10)),
         Step("pre_cleanup", PerformAction("pre_cleanup"),
              timedelta(seconds=10)),
         Step("cleanup", PerformAction("cleanup"), timedelta(seconds=10)),
         Step("post_cleanup", PerformAction("post_cleanup"),
              timedelta(seconds=10)),
     ]
     metrics_steps = [
         Step("pre_generate_metrics", PerformAction("pre_generate_metrics"),
              timedelta(seconds=10)),
         Step("generate_metrics", PerformAction("generate_metrics"),
              timedelta(seconds=10)),
         Step("post_generate_metrics",
              PerformAction("post_generate_metrics"),
              timedelta(seconds=10)),
     ]
     return [
         Workflow(
             uid="collect",
             name="collect",
             steps=collect_steps + metrics_steps,
             triggers=[EventTrigger("start_collect_workflow")],
             on_surpass=TaskSurpassBehaviour.Wait,
         ),
         Workflow(
             uid="cleanup",
             name="cleanup",
             steps=cleanup_steps + metrics_steps,
             triggers=[EventTrigger("start_cleanup_workflow")],
             on_surpass=TaskSurpassBehaviour.Wait,
         ),
         Workflow(
             uid="metrics",
             name="metrics",
             steps=metrics_steps,
             triggers=[EventTrigger("start_metrics_workflow")],
             on_surpass=TaskSurpassBehaviour.Wait,
         ),
         Workflow(
             uid="collect_and_cleanup",
             name="collect_and_cleanup",
             steps=collect_steps + cleanup_steps + metrics_steps,
             triggers=[
                 EventTrigger("start_collect_and_cleanup_workflow"),
                 TimeTrigger("0 * * * *")
             ],
             on_surpass=TaskSurpassBehaviour.Wait,
         ),
     ]
示例#6
0
 def workflow(name: TaskDescriptorId, steps: List[Step]) -> Workflow:
     trigger: List[Trigger] = [EventTrigger(f"start_{name}_workflow")]
     wf_config = config.workflows.get(name)
     if wf_config:
         trigger.append(TimeTrigger(wf_config.schedule))
     return Workflow(uid=name, name=name, steps=steps, triggers=trigger, on_surpass=TaskSurpassBehaviour.Wait)