Workflow graph - collection of tasks.
Variables: task – collection of tasks, dict with tasks name as key
Check workflow graph - if some task is missing, all task are marked properly as start, join or end points, …
Raises: WorkflowError – when there are some problems with workflow graph
List of names of tasks that are marked as end points.
Load tasks from module and add them to workflow graph. Can be also module name, then module will be get from sys.module by that name.
Raises: WorkflowError – if name of loaded task is not unique
List of names of tasks that are marked as start points.
Workflow execution engine.
- workflow –
- context – arbitrary user object, passed to all tasks
- state – state of execution
Dump runner to file. Stored dump contains
stateso runner execution can be restored and finished later.
Workflow execution finished. True when reached end points and there is no task that should be executed.
Execute tasks from workflow.
Some tasks might end in state in which they cannot be executed (waiting for external event or join point waiting for preceding tasks). If there is no task that can be executed run will stop executing and
finishedproperty will be
False. In that case run should be called again (with some delay or runner can be dumped to file by
dump()and executed later).
TaskStatefor list of task states.
- workflow –
Task(func, name=NOTHING, labels=NOTHING)¶
Workflow task. Wraps function for use in workflow.
Wrapped function must accept context from
Runnervia only parameter and should return
Falsewhether task was completed and execution can continue with following tasks.
If wrapped function returned
Falseexecution will stop and task will be executed again in next run. This way can be implemented waiting, eg. for external event.
- function – wrapped function
- name – task name (by default function name)
- labels – task labels
- followed_by – connection to next tasks (set of
- preceded_by – names of preceding tasks, generated by
- is_start_point – task is start point of workflow
- is_join_point – task is join point of multiple tasks
- is_end_point – task is end point of workflow
has_labels(labels, reducer=<built-in function any>)¶
Check if task has labels.
Reducer is used to reduce multi-labels check to single boolean value. all checks if task have all labels, any checks if task has at least one of labels.
Enumeration of task states.
- NEW – task new in queue
- WAITING – task is waiting, function returned
- BLOCKED – task is waiting for completion of preceding tasks
- READY – task is ready for execution
- COMPLETE – task was executed and will be expanded
- CANCELED – task was not executed because transition condition was not met
Transition to following task.
- dest – name of following task
- cond – condition whether following task should be executed, function
that will receive context from
Runnerand must return bool (allows to create conditional branching and looping in graph)
Generic workflow error.
Utility to collect function decorators and execute them in reverse order at once.
Add decorator to stack.
Apply decorators to func and return new func created by chain of decorators.
Return value of each function is used as argument of next function and first function will receive
Decorator to mark function as workflow task. See
Taskfor arguments documentation.
Add transition to next task. See
Transitionfor arguments documentation.