Skip to content

Parallel Group

Tasks are organized into named groups. Groups run in parallel, but tasks within each group run sequentially, passing context between them.

Implementation

from time import sleep

from dotflow import DotFlow, action, Context


@action
def task_foo(initial_context: Context):
    sleep(2)
    value = initial_context.storage
    return value * value * value


@action
def task_bar(initial_context: Context):
    sleep(1)
    value = initial_context.storage
    return value * value * value


def main():
    workflow = DotFlow()

    workflow.task.add(step=task_foo, initial_context=10, group_name="foo")
    workflow.task.add(step=task_bar, initial_context=10, group_name="bar")

    workflow.start()

    return workflow


if __name__ == "__main__":
    main()

Workflow

flowchart TD
    A[Start] -->|run| C(Parallel Groups)
    C -->|run| D[task_a]
    C -->|run| E[task_c]
    D -->|response| X[task_b]
    X --> H[Finish]
    E -->|response| Y[task_d]
    Y --> H[Finish]

References