mistral.workflow package

Submodules

mistral.workflow.base module

class mistral.workflow.base.WorkflowController(wf_ex, wf_spec=None)

Bases: object

Workflow Controller base class.

Different workflow controllers implement different workflow algorithms. In practice it may actually mean that there may be multiple ways of describing workflow models (and even languages) that will be supported by Mistral.

all_errors_handled()

Determines if all errors (if any) are handled.

Returns:True if either there aren’t errors at all or all errors are considered handled.
any_cancels()

Determines if there are any task cancellations.

Returns:True if there is one or more tasks in cancelled state.
continue_workflow(*args, **kwargs)

Calculates a list of commands to continue the workflow.

Given a workflow specification this method makes required analysis according to this workflow type rules and identifies a list of commands needed to continue the workflow.

Parameters:task_ex – Task execution that caused workflow continuation. Optional. If not specified, it means that no certain task caused this operation (e.g. workflow has been just started or resumed manually).
Returns:List of workflow commands (instances of mistral.workflow.commands.WorkflowCommand).
evaluate_workflow_final_context()

Evaluates final workflow context assuming that workflow has finished.

Returns:Final workflow context.
get_logical_task_state(task_ex)

Determines a logical state of the given task.

Parameters:task_ex – Task execution.
Returns:Tuple (state, state_info, cardinality) where ‘state’ and ‘state_info’ are the corresponding values which the given
task should have according to workflow rules and current

states of other tasks. ‘cardinality’ gives the estimation on the number of preconditions that are not yet met in case if state is WAITING. This number can be used to estimate how frequently we can refresh the state of this task.

get_task_inbound_context(task_spec)
is_error_handled_for(task_ex)

Determines if error is handled for specific task.

Parameters:task_ex – Task execution.
Returns:True if either there is no error at all or error is considered handled.
rerun_tasks(task_execs, reset=True)

Gets commands to rerun existing task executions.

Parameters:
  • task_execs – List of task executions.
  • reset – If true, then purge action executions for the tasks.
Returns:

List of workflow commands.

mistral.workflow.commands module

class mistral.workflow.commands.FailWorkflow(wf_ex, wf_spec, task_spec, ctx, msg=None)

Bases: mistral.workflow.commands.SetWorkflowState

Instruction to fail a workflow.

class mistral.workflow.commands.Noop(wf_ex, wf_spec, task_spec, ctx)

Bases: mistral.workflow.commands.WorkflowCommand

No-operation command.

class mistral.workflow.commands.PauseWorkflow(wf_ex, wf_spec, task_spec, ctx, msg=None)

Bases: mistral.workflow.commands.SetWorkflowState

Instruction to pause a workflow.

class mistral.workflow.commands.RunExistingTask(wf_ex, wf_spec, task_ex, reset=True)

Bases: mistral.workflow.commands.WorkflowCommand

Command for running already existent task.

class mistral.workflow.commands.RunTask(wf_ex, wf_spec, task_spec, ctx)

Bases: mistral.workflow.commands.WorkflowCommand

Instruction to run a workflow task.

get_unique_key()
is_waiting()
class mistral.workflow.commands.SetWorkflowState(wf_ex, wf_spec, task_spec, ctx, new_state, msg)

Bases: mistral.workflow.commands.WorkflowCommand

Instruction to change a workflow state.

class mistral.workflow.commands.SucceedWorkflow(wf_ex, wf_spec, task_spec, ctx, msg=None)

Bases: mistral.workflow.commands.SetWorkflowState

Instruction to succeed a workflow.

class mistral.workflow.commands.WorkflowCommand(wf_ex, wf_spec, task_spec, ctx)

Bases: object

Workflow command.

A set of workflow commands form a communication protocol between workflow handler and its clients. When workflow handler makes a decision about how to continue a workflow it returns a set of commands so that a caller knows what to do next.

mistral.workflow.data_flow module

class mistral.workflow.data_flow.ContextView(*dicts)

Bases: dict

Workflow context view.

It’s essentially an immutable composite structure providing fast lookup over multiple dictionaries w/o having to merge those dictionaries every time. The lookup algorithm simply iterates over provided dictionaries one by one and returns a value taken from the first dictionary where the provided key exists. This means that these dictionaries must be provided in the order of decreasing priorities.

Note: Although this class extends built-in ‘dict’ it shouldn’t be considered a normal dictionary because it may not implement all methods and account for all corner cases. It’s only a read-only view.

clear()
get(key, default=None)
items()
iteritems()
iterkeys()
itervalues()
keys()
pop(k, d=None)
popitem()
update(E=None, **F)
values()

mistral.workflow.direct_workflow module

class mistral.workflow.direct_workflow.DirectWorkflowController(wf_ex, wf_spec=None)

Bases: mistral.workflow.base.WorkflowController

‘Direct workflow’ handler.

This handler implements the workflow pattern which is based on direct transitions between tasks, i.e. after each task completion a decision should be made which tasks should run next based on result of task execution. Note, that tasks can run in parallel. For example, if there’s a workflow consisting of three tasks ‘A’, ‘B’ and ‘C’ where ‘A’ starts first then ‘B’ and ‘C’ can start second if certain associated with transition ‘A’->’B’ and ‘A’->’C’ evaluate to true.

all_errors_handled()
evaluate_workflow_final_context()
get_logical_task_state(task_ex)
is_error_handled_for(task_ex)

mistral.workflow.lookup_utils module

The intention of the module is providing various DB related lookup functions
for more convenient usage within the workflow engine.

Some of the functions may provide caching capabilities.

WARNING: Oftentimes, persistent objects returned by the methods in this module won’t be attached to the current DB SQLAlchemy session because they are returned from the cache and therefore they need to be used carefully without trying to do any lazy loading etc. These objects are also not suitable for re-attaching them to a session in order to update their persistent DB state. Mostly, they are useful for doing any kind of fast lookups with in order to make some decision based on their state.

mistral.workflow.reverse_workflow module

class mistral.workflow.reverse_workflow.ReverseWorkflowController(wf_ex, wf_spec=None)

Bases: mistral.workflow.base.WorkflowController

‘Reverse workflow controller.

This controller implements the workflow pattern which is based on dependencies between tasks, i.e. each task in a workflow graph may be dependent on other tasks. To run this type of workflow user must specify a task name that serves a target node in the graph that the algorithm should come to by resolving all dependencies. For example, if there’s a workflow consisting of two tasks ‘A’ and ‘B’ where ‘A’ depends on ‘B’ and if we specify a target task name ‘A’ then the controller first will run task ‘B’ and then, when a dependency of ‘A’ is resolved, will run task ‘A’.

all_errors_handled()
evaluate_workflow_final_context()
get_logical_task_state(task_ex)
is_error_handled_for(task_ex)

mistral.workflow.states module

Valid task and workflow states.

mistral.workflow.utils module

class mistral.workflow.utils.Result(data=None, error=None, cancel=False)

Bases: mistral.serialization.MistralSerializable

Explicit data structure containing a result of task execution.

cut_repr()
is_cancel()
is_error()
is_success()
to_dict()
class mistral.workflow.utils.ResultSerializer

Bases: mistral.serialization.DictBasedSerializer

deserialize_from_dict(entity_dict)
serialize_to_dict(entity)

Module contents