Skip to content

Worker Execution Entity

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

from everysk.sdk.entities import WorkerExecution


Attributes

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

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

  • status: The current execution status of the worker. Possible values are defined by the platform (e.g. PREPARING, RUNNING, OK, ERROR).

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

  • result: An object containing the outcome of the execution, with the following fields:

  • status: Result status — OK, ERROR, or UNKNOW.
  • data: The output data returned by the worker.
  • log: A list of log entries produced during execution.

  • input_params: An object containing the input parameters passed to the worker, including:

  • worker_id: The ID of the worker.
  • workflow_id: The ID of the parent workflow.
  • workspace: The workspace in which the worker runs.
  • script_inputs: A dictionary of script-level inputs.
  • parallel_info: Parallel execution metadata (index and length).

  • parallel_info: Metadata about parallel execution, with index (current shard) and length (total shards).

  • start_time: When the worker execution started.

  • end_time: When the worker execution ended.

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

  • cpu_time: CPU time consumed during execution.

  • process_cpu_time: Process-level CPU time consumed.

  • workflow_execution_id: The ID of the parent Workflow Execution.

  • workflow_id: The ID of the workflow this worker belongs to.

  • workflow_name: The name of the workflow.

  • worker_id: The ID of the worker definition.

  • worker_name: The name of the worker.

  • worker_type: The template type of the worker.


Instantiating a Worker Execution Entity

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

worker_execution = WorkerExecution()
type(worker_execution)
everysk.sdk.entities.worker_execution.base.WorkerExecution


Retrieving a Worker Execution

To retrieve an existing Worker Execution by its ID:

worker_execution = WorkerExecution.retrieve('wkex_3bNhXpQrLo7TmK2sJfGvWe1cA')
print(worker_execution.status)
print(worker_execution.duration)


Retrieving Input Params

The Worker Execution entity provides a class method get_input_params() that retrieves the InputParams object of a worker execution by its ID.

params = WorkerExecution.get_input_params('wkex_3bNhXpQrLo7TmK2sJfGvWe1cA')
print(params.worker_id)
print(params.workflow_id)

If the ID is invalid or the entity is not found, a ValueError is raised:

WorkerExecution.get_input_params('invalid_id')
# ValueError: Invalid Entity ID: invalid_id


Querying Worker Executions

Worker executions can be queried by their parent workflow execution:

worker_execution = WorkerExecution(workflow_execution_id='wfex_T1eYymTSIptJ4Hyt1Z6p4uGOe')
results = worker_execution.query()

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


Convert Worker 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:

worker_execution = WorkerExecution()
type(worker_execution)
everysk.sdk.entities.worker_execution.base.WorkerExecution

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