Patterns

class taskflow.flow.Flow(name, retry=None)[source]

Bases: object

The base abstract class of all flow implementations.

A flow is a structure that defines relationships between tasks. You can add tasks and other flows (as subflows) to the flow, and the flow provides a way to implicitly or explicitly define how they are interdependent. Exact structure of the relationships is defined by concrete implementation, while this class defines common interface and adds human-readable (not necessary unique) name.

NOTE(harlowja): if a flow is placed in another flow as a subflow, a desired way to compose flows together, then it is valid and permissible that during compilation the subflow & parent flow may be flattened into a new flow.

name

A non-unique name for this flow (human readable).

retry

The associated flow retry controller.

This retry controller object will affect & control how (and if) this flow and its contained components retry when execution is underway and a failure occurs.

add(*items)[source]

Adds a given item/items to this flow.

Iterates over dependency links between children of the flow.

Iterates over 3-tuples (A, B, meta), where
  • A is a child (atom or subflow) link starts from;
  • B is a child (atom or subflow) link points to; it is said that B depends on A or B requires A;
  • meta is link metadata, a dictionary.
provides

Set of symbol names provided by the flow.

requires

Set of unsatisfied symbol names required by the flow.

Linear flow

class taskflow.patterns.linear_flow.Flow(name, retry=None)[source]

Bases: taskflow.flow.Flow

Linear flow pattern.

A linear (potentially nested) flow of tasks/flows that can be applied in order as one unit and rolled back as one unit using the reverse order that the tasks/flows have been applied in.

add(*items)[source]

Adds a given task/tasks/flow/flows to this flow.

Unordered flow

class taskflow.patterns.unordered_flow.Flow(name, retry=None)[source]

Bases: taskflow.flow.Flow

Unordered flow pattern.

A unordered (potentially nested) flow of tasks/flows that can be executed in any order as one unit and rolled back as one unit.

add(*items)[source]

Adds a given task/tasks/flow/flows to this flow.

Graph flow

class taskflow.patterns.graph_flow.Flow(name, retry=None)[source]

Bases: taskflow.flow.Flow

Graph flow pattern.

Contained flows/tasks will be executed according to their dependencies which will be resolved by using the flows/tasks provides and requires mappings or by following manually created dependency links.

From dependencies directed graph is build. If it has edge A -> B, this means B depends on A.

Note: Cyclic dependencies are not allowed.

Link existing node u as a runtime dependency of existing node v.

Parameters:
  • u – task or flow to create a link from (must exist already)
  • v – task or flow to create a link to (must exist already)
  • decider – A callback function that will be expected to decide at runtime whether v should be allowed to execute (or whether the execution of v should be ignored, and therefore not executed). It is expected to take as single keyword argument history which will be the execution results of all u decideable links that have v as a target. It is expected to return a single boolean (True to allow v execution or False to not).
add(*nodes, **kwargs)[source]

Adds a given task/tasks/flow/flows to this flow.

Parameters:
  • nodes – node(s) to add to the flow
  • kwargs

    keyword arguments, the two keyword arguments currently processed are:

    • resolve_requires a boolean that when true (the default) implies that when node(s) are added their symbol requirements will be matched to existing node(s) and links will be automatically made to those providers. If multiple possible providers exist then a AmbiguousDependency exception will be raised.
    • resolve_existing, a boolean that when true (the default) implies that on addition of a new node that existing node(s) will have their requirements scanned for symbols that this newly added node can provide. If a match is found a link is automatically created from the newly added node to the requiree.
class taskflow.patterns.graph_flow.TargetedFlow(*args, **kwargs)[source]

Bases: taskflow.patterns.graph_flow.Flow

Graph flow with a target.

Adds possibility to execute a flow up to certain graph node (task or subflow).

set_target(target_node)[source]

Set target for the flow.

Any node(s) (tasks or subflows) not needed for the target node will not be executed.

reset_target()[source]

Reset target for the flow.

All node(s) of the flow will be executed.

add(*args, **kwargs)

Adds a given task/tasks/flow/flows to this flow.

Parameters:
  • nodes – node(s) to add to the flow
  • kwargs

    keyword arguments, the two keyword arguments currently processed are:

    • resolve_requires a boolean that when true (the default) implies that when node(s) are added their symbol requirements will be matched to existing node(s) and links will be automatically made to those providers. If multiple possible providers exist then a AmbiguousDependency exception will be raised.
    • resolve_existing, a boolean that when true (the default) implies that on addition of a new node that existing node(s) will have their requirements scanned for symbols that this newly added node can provide. If a match is found a link is automatically created from the newly added node to the requiree.

Link existing node u as a runtime dependency of existing node v.

Parameters:
  • u – task or flow to create a link from (must exist already)
  • v – task or flow to create a link to (must exist already)
  • decider – A callback function that will be expected to decide at runtime whether v should be allowed to execute (or whether the execution of v should be ignored, and therefore not executed). It is expected to take as single keyword argument history which will be the execution results of all u decideable links that have v as a target. It is expected to return a single boolean (True to allow v execution or False to not).

Hierarchy

digraph inheritance9736092c38 { rankdir=LR; size="8.0, 12.0"; "flow.Flow" [style="setlinewidth(0.5)",URL="#taskflow.flow.Flow",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",tooltip="The base abstract class of all flow implementations.",height=0.25,shape=box,fontsize=10]; "graph_flow.Flow" [style="setlinewidth(0.5)",URL="#taskflow.patterns.graph_flow.Flow",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",tooltip="Graph flow pattern.",height=0.25,shape=box,fontsize=10]; "flow.Flow" -> "graph_flow.Flow" [arrowsize=0.5,style="setlinewidth(0.5)"]; "graph_flow.TargetedFlow" [style="setlinewidth(0.5)",URL="#taskflow.patterns.graph_flow.TargetedFlow",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",tooltip="Graph flow with a target.",height=0.25,shape=box,fontsize=10]; "graph_flow.Flow" -> "graph_flow.TargetedFlow" [arrowsize=0.5,style="setlinewidth(0.5)"]; "linear_flow.Flow" [style="setlinewidth(0.5)",URL="#taskflow.patterns.linear_flow.Flow",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",tooltip="Linear flow pattern.",height=0.25,shape=box,fontsize=10]; "flow.Flow" -> "linear_flow.Flow" [arrowsize=0.5,style="setlinewidth(0.5)"]; "unordered_flow.Flow" [style="setlinewidth(0.5)",URL="#taskflow.patterns.unordered_flow.Flow",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",tooltip="Unordered flow pattern.",height=0.25,shape=box,fontsize=10]; "flow.Flow" -> "unordered_flow.Flow" [arrowsize=0.5,style="setlinewidth(0.5)"]; }