Workflow Tasks Graph

class cloudify.workflows.tasks_graph.TaskDependencyGraph(workflow_context, default_subgraph_task_config=None)[source]

Bases: object

A task graph builder

Parameters:workflow_context – A WorkflowContext instance (used for logging)

Add a WorkflowTask to this graph

Parameters:task – The task

Get a task instance that was inserted to this graph by its id

Parameters:task_id – the task id
Returns:a WorkflowTask instance for the requested task if found. None, otherwise.

Remove the provided task from the graph

Parameters:task – The task
add_dependency(src_task, dst_task)[source]

Add a dependency between tasks. The source task will only be executed after the target task terminates. A task may depend on several tasks, in which case it will only be executed after all its ‘destination’ tasks terminate

  • src_task – The source task
  • dst_task – The target task
Returns:a new TaskSequence for this graph

Start executing the graph based on tasks and dependencies between them. Calling this method will block until one of the following occurs:

  1. all tasks terminated
  2. a task failed
  3. an unhandled exception is raised
  4. the execution is cancelled

Note: This method will raise an api.ExecutionCancelled error if the execution has been cancelled. When catching errors raised from this method, make sure to re-raise the error if it’s api.ExecutionsCancelled in order to allow the execution to be set in cancelled mode properly.

Also note that for the time being, if such a cancelling event occurs, the method might return even while there’s some operations still being executed.


An iterator on tasks added to the graph

class cloudify.workflows.tasks_graph.forkjoin(*tasks)[source]

Bases: object

A simple wrapper for tasks. Used in conjunction with TaskSequence. Defined to make the code easier to read (instead of passing a list) see TaskSequence.add for more details

class cloudify.workflows.tasks_graph.TaskSequence(graph)[source]

Bases: object

Helper class to add tasks in a sequential manner to a task dependency graph

Parameters:graph – The TaskDependencyGraph instance

Add tasks to the sequence.


Each task might be:

  • A WorkflowTask instance, in which case, it will be added to the graph with a dependency between it and the task previously inserted into the sequence
  • A forkjoin of tasks, in which case it will be treated as a “fork-join” task in the sequence, i.e. all the fork-join tasks will depend on the last task in the sequence (could be fork join) and the next added task will depend on all tasks in this fork-join task
class cloudify.workflows.tasks_graph.SubgraphTask(name, graph, task_id=None, info=None, on_success=None, on_failure=None, total_retries=0, retry_interval=30, send_task_events=True)[source]

Bases: cloudify.workflows.tasks.WorkflowTask

add_dependency(src_task, dst_task)[source]
task_terminated(task, new_task=None)[source]