Skip to content

Workflow Execution Entity

The Workflow Execution entity is kept under the following import statement:

from everysk.sdk.entities import WorkflowExecution


Attributes

Below we have the most common attributes used in the Workflow Execution entity:

  • id: The unique identifier of the Workflow Execution entity. Follows the format wfex_<value>.

  • run_status: The outcome of the workflow execution. It is RUNNING while the workflow runs, then SUCCEEDED or FAILED. CANCELED is reserved and is not written by the server today.

  • execution_type: How the workflow was triggered (e.g. scheduled, manual).

  • start_time: When the workflow execution started.

  • end_time: When the workflow execution ended.

  • duration: Total wall-clock duration of the execution in seconds.

  • real_execution_time: The actual computation time of the execution.

  • total_execution_time: The sum of all worker execution times within this workflow execution.

  • workflow_id: The ID of the workflow definition being executed.

  • workflow_name: The name of the workflow.

  • workspace: The workspace in which the workflow runs.

  • started_worker_id: The ID of the worker that started the execution.

  • ender_worker_id: The ID of the worker that ended the execution.

  • ender_worker_execution_id: The execution ID of the worker that ended the execution.

  • worker_ids: A list of all worker IDs involved in this workflow execution.

  • resume: A list of checkpoint data used to resume the workflow execution.

Legacy: the entity also carries a status field (OK, then COMPLETED). It is deprecated and does not say whether the run succeeded. Ignore it.


Instantiating a Workflow Execution Entity

To instantiate a Workflow Execution entity, we can use the following code snippet:

workflow_execution = WorkflowExecution()
type(workflow_execution)
everysk.sdk.entities.workflow_execution.base.WorkflowExecution


Retrieving a Workflow Execution

To retrieve an existing Workflow Execution by its ID:

workflow_execution = WorkflowExecution.retrieve('wfex_T1eYymTSIptJ4Hyt1Z6p4uGOe')
print(workflow_execution.run_status)
print(workflow_execution.duration)


Waiting for a Workflow Execution

Use wait_for_completion() to poll a Workflow Execution until run_status leaves RUNNING, then get_result() to read the Ender's result:

execution = WorkflowExecution.retrieve('wfex_T1eYymTSIptJ4Hyt1Z6p4uGOe').wait_for_completion(timeout=300, poll_interval=2)

if execution.run_status == 'SUCCEEDED':
    worker_execution = execution.get_result()
    print(worker_execution.result)
else:
    print(f'Workflow execution failed with run_status: {execution.run_status}')

wait_for_completion raises WorkflowExecutionTimeout if the run does not finish within timeout seconds (default 300; it polls every poll_interval seconds, default 2). It does not judge the run: when run_status is FAILED, wait_for_completion still returns the finished execution, and get_result() raises WorkflowExecutionFailed instead of returning a result.


Querying Workflow Executions

Workflow executions can be queried by their parent workflow:

workflow_execution = WorkflowExecution(workflow_id='wrkf_P95OLO61oGM5NwFn3W4iMl7rs')
results = workflow_execution.query()

for execution in results:
    print(execution.id, execution.run_status, execution.duration)


Convert Workflow Execution to a Dictionary

Most times when working with entities, there might be a point where we need to convert the entity to a dictionary, and to achieve this we simply use the to_dict() method:

workflow_execution = WorkflowExecution()
type(workflow_execution)
everysk.sdk.entities.workflow_execution.base.WorkflowExecution

to_dict = workflow_execution.to_dict()
type(to_dict)
# dict