flowserv.model.workflow.state module
Definition of workflow states. The classes in this module represent the different possible states of a workflow run. There are four different states: (PENDING) the workflow run has been submitted and is waiting to start running, (RUNNING) the workflow is actively executing at the moment, (ERROR) workflow execution was interrupted by an error or canceled by the user, (SUCCESS) the workflow run completed successfully.
Contains default methods to (de-)serialize workflow state.
- flowserv.model.workflow.state.CANCELED = ['canceled at user request']
Definition of state type identifier.
- flowserv.model.workflow.state.STATE_SUCCESS = 'SUCCESS'
Short cut to list of active states.
- class flowserv.model.workflow.state.StateCanceled(created_at: str, started_at: Optional[str] = None, stopped_at: Optional[str] = None, messages: Optional[List[str]] = None)
Bases:
flowserv.model.workflow.state.WorkflowStateCancel state representation for a workflow run. The workflow has three timestamps: the workflow creation time, workflow run start time and the time when the workflow was canceled. The state also maintains an optional list of messages.
- class flowserv.model.workflow.state.StateError(created_at: str, started_at: Optional[str] = None, stopped_at: Optional[str] = None, messages: Optional[List[str]] = None)
Bases:
flowserv.model.workflow.state.WorkflowStateError state representation for a workflow run. The workflow has three timestamps: the workflow creation time, workflow run start time and the time at which the error occured (ot workflow was canceled). The state also maintains an optional list of error messages.
- class flowserv.model.workflow.state.StatePending(created_at: Optional[str] = None)
Bases:
flowserv.model.workflow.state.WorkflowStateState representation for a pending workflow that is waiting to start running. The workflow has only one timestamp representing the workflow creation time.
- cancel(messages: Optional[List[str]] = None) flowserv.model.workflow.state.StateCanceled
Get instance of canceled state for a pending wokflow.
Since the workflow did not start to run the started_at timestamp is set to the current time just like the stopped_at timestamp.
- Parameters
messages (list(string), optional) – Optional list of messages
- Return type
- error(messages: Optional[List[str]] = None) flowserv.model.workflow.state.StateError
Get instance of error state for a pending wokflow. If the exception that caused the workflow execution to terminate is given it will be used to create the list of error messages.
Since the workflow did not start to run the started_at timestamp is set to the current time just like the stopped_at timestamp.
- Parameters
messages (list(string), optional) – Optional list of error messages
- Return type
- start() flowserv.model.workflow.state.StateRunning
Get instance of running state with the same create at timestamp as this state and the started at with the current timestamp.
- Return type
- success(files: Optional[List[str]] = None) flowserv.model.workflow.state.StateSuccess
Get instance of success state for a competed wokflow.
- Parameters
files (list(string), default=None) – Optional list of created files (relative path).
- Return type
- class flowserv.model.workflow.state.StateRunning(created_at: str, started_at: Optional[str] = None)
Bases:
flowserv.model.workflow.state.WorkflowStateState representation for a active workflow run. The workflow has two timestamps: the workflow creation time and the workflow run start time.
- cancel(messages: Optional[List[str]] = None) flowserv.model.workflow.state.StateCanceled
Get instance of class cancel state for a running wokflow.
- Parameters
messages (list(string), optional) – Optional list of messages
- Return type
- error(messages: Optional[List[str]] = None) flowserv.model.workflow.state.StateError
Get instance of error state for a running wokflow. If the exception that caused the workflow execution to terminate is given it will be used to create the list of error messages.
- Parameters
messages (list(string), optional) – Optional list of error messages
- Return type
- success(files: Optional[List[str]] = None) flowserv.model.workflow.state.StateSuccess
Get instance of success state for a competed wokflow.
- Parameters
files (list(string), default=None) – Optional list of created files (relative path).
- Return type
- class flowserv.model.workflow.state.StateSuccess(created_at: str, started_at: str, finished_at: Optional[str] = None, files: Optional[List[str]] = None)
Bases:
flowserv.model.workflow.state.WorkflowStateSuccess state representation for a workflow run. The workflow has three timestamps: the workflow creation time, workflow run start time and the time when the workflow execution finished. The state also maintains handles to any files that were created by the workflow run.
- class flowserv.model.workflow.state.WorkflowState(type_id: str, created_at: Optional[str] = None)
Bases:
objectThe base class for workflow states contains the state type identifier that is used by the different state type methods. The state also maintains the timestamp of workflow run creation. Subclasses will add additional timestamps and properties.
- is_active() bool
A workflow is in active state if it is either pending or running.
- Return type
bool
- is_canceled() bool
Returns True if the workflow state is of type CANCELED.
- Return type
bool
- is_error() bool
Returns True if the workflow state is of type ERROR.
- Return type
bool
- is_pending() bool
Returns True if the workflow state is of type PENDING.
- Return type
bool
- is_running() bool
Returns True if the workflow state is of type RUNNING.
- Return type
bool
- is_success() bool
Returns True if the workflow state is of type SUCCESS.
- Return type
bool
- flowserv.model.workflow.state.deserialize_state(doc)
Create instance of workflow state from a given dictionary serialization.
- Parameters
doc (dict) – Serialization if the workflow state
- Return type
- Raises
KeyError –
ValueError –
- flowserv.model.workflow.state.serialize_state(state)
Create dictionary serialization if a given workflow state.
- Parameters
state (flowserv.model.workflow.state.WorkflowState) – Workflow state
- Return type
dict