pynenc.state_backend.base_state_backend¶
Module Contents¶
Classes¶
Data structure representing the history of a task invocation. |
|
Abstract base class for state backends in a distributed task system. |
API¶
- class pynenc.state_backend.base_state_backend.InvocationHistory[source]¶
Data structure representing the history of a task invocation.
Stores the invocation ID, timestamp, status, and execution context. Provides methods for serialization and deserialization to and from JSON.
- Variables:
invocation_id – Unique identifier of the invocation.
_timestamp – Timestamp of the invocation history creation.
status – Current status of the invocation.
execution_context – Context of the execution, reserved for future use.
- _timestamp: datetime.datetime¶
‘field(…)’
- status: Optional[pynenc.invocation.status.InvocationStatus]¶
None
- property timestamp: datetime.datetime¶
Returns the timestamp of the invocation history.
- to_json() str[source]¶
Serializes the invocation history to a JSON string.
- Returns:
A JSON representation of the invocation history.
- classmethod from_json(json_str: str) pynenc.state_backend.base_state_backend.InvocationHistory[source]¶
Deserializes a JSON string into an InvocationHistory object.
- Parameters:
json_str (str) – JSON string to deserialize.
- Returns:
An instance of InvocationHistory.
- class pynenc.state_backend.base_state_backend.BaseStateBackend(app: pynenc.app.Pynenc)[source]¶
Bases:
abc.ABCAbstract base class for state backends in a distributed task system.
Manages storage and retrieval of invocation-related data, including execution status, history, results, and exceptions.
Initialization
- wait_for_all_async_operations() None[source]¶
Waits for all asynchronous operations related to invocation status to complete.
- wait_for_invocation_async_operations(invocation_id: str) None[source]¶
Waits for all asynchronous operations for a specific invocation to complete.
- Parameters:
invocation_id (str) – ID of the invocation.
- abstract _upsert_invocation(invocation: DistributedInvocation[Params, Result]) None[source]¶
Updates or inserts an invocation.
- Parameters:
invocation (DistributedInvocation) – The invocation to upsert.
- abstract _get_invocation(invocation_id: str) Optional[pynenc.invocation.dist_invocation.DistributedInvocation][source]¶
Retrieves an invocation by its ID.
- abstract _add_history(invocation: DistributedInvocation[Params, Result], invocation_history: pynenc.state_backend.base_state_backend.InvocationHistory) None[source]¶
Adds a history record for an invocation.
- abstract _get_history(invocation: DistributedInvocation[Params, Result]) list[pynenc.state_backend.base_state_backend.InvocationHistory][source]¶
Retrieves the history of an invocation.
- Parameters:
invocation (DistributedInvocation) – The invocation to get the history from
- abstract _get_result(invocation: DistributedInvocation[Params, Result]) pynenc.types.Result[source]¶
Retrieves the result of an invocation.
- Parameters:
invocation (DistributedInvocation) – The invocation to get the result from
- abstract _set_result(invocation: DistributedInvocation[Params, Result], result: pynenc.types.Result) None[source]¶
Sets the result of an invocation.
- Parameters:
invocation (DistributedInvocation) – The invocation to set
result (Result) – The result to set
- abstract _get_exception(invocation: DistributedInvocation[Params, Result]) Exception[source]¶
Retrieves the exception of an invocation.
- Parameters:
invocation (DistributedInvocation) – The invocation to get the exception from
- abstract _set_exception(invocation: DistributedInvocation[Params, Result], exception: Exception) None[source]¶
Sets the raised exception by an invocation ran.
- Parameters:
invocation (DistributedInvocation) – The invocation to set
exception (Exception) – The exception raised
- upsert_invocation(invocation: pynenc.invocation.dist_invocation.DistributedInvocation) None[source]¶
Starts an asynchronous operation to update or insert an invocation.
- Parameters:
invocation (DistributedInvocation) – The invocation to upsert.
- get_invocation(invocation_id: str) pynenc.invocation.dist_invocation.DistributedInvocation[source]¶
Retrieves an invocation by its ID, raising an error if not found.
- Parameters:
invocation_id (DistributedInvocation) – ID of the invocation.
- Returns:
The retrieved invocation.
- Raises:
InvocationNotFoundError – If the invocation wasn’t found.
- add_history(invocation: DistributedInvocation[Params, Result], status: Optional[pynenc.invocation.status.InvocationStatus] = None, execution_context: Optional[Any] = None) None[source]¶
Adds a history record for an invocation.
- Parameters:
invocation (DistributedInvocation) – The invocation to add history for.
status (Optional[InvocationStatus]) – The status of the invocation.
execution_context (Optional[Any]) – The execution context of the invocation.
- get_history(invocation: DistributedInvocation[Params, Result]) list[pynenc.state_backend.base_state_backend.InvocationHistory][source]¶
Retrieves the history of an invocation.
- Parameters:
invocation (DistributedInvocation) – The invocation to retrieve history for.
- Returns:
A list of invocation history records.
- set_result(invocation: pynenc.invocation.dist_invocation.DistributedInvocation, result: pynenc.types.Result) None[source]¶
Sets the result of an invocation.
- Parameters:
invocation (DistributedInvocation) – The invocation to set the result for.
result (Result) – The result of the invocation.
- get_result(invocation: DistributedInvocation[Params, Result]) pynenc.types.Result[source]¶
Retrieves the result of an invocation.
- Parameters:
invocation (DistributedInvocation) – The invocation to retrieve the result for.
- Returns:
The result of the invocation.
- set_exception(invocation: pynenc.invocation.dist_invocation.DistributedInvocation, exception: Exception) None[source]¶
Sets the exception of an invocation.
- Parameters:
invocation (DistributedInvocation) – The invocation to set the exception for.
exception (Exception) – The exception of the invocation.
- get_exception(invocation: DistributedInvocation[Params, Result]) Exception[source]¶
Retrieves the exception of an invocation.
- Parameters:
invocation (DistributedInvocation) – The invocation to retrieve the exception for.
- Returns:
The exception of the invocation.
- abstract set_workflow_data(workflow_identity: pynenc.workflow.WorkflowIdentity, key: str, value: Any) None[source]¶
Set a value in workflow data.
- Parameters:
workflow_identity – Workflow identity
key – Data key to set
value – Value to store
- abstract get_workflow_data(workflow_identity: pynenc.workflow.WorkflowIdentity, key: str, default: Any = None) Any[source]¶
Get a value from workflow data.
- Parameters:
workflow_identity – Workflow identity
key – Data key to retrieve
default – Default value if key doesn’t exist
- Returns:
Stored value or default
- abstract get_workflow_deterministic_value(workflow: pynenc.workflow.WorkflowIdentity, key: str) Any[source]¶
Get a stored deterministic value for a workflow.
- Parameters:
workflow_identity – Workflow identity
key – Value key
- Returns:
Stored value or None if not found
- abstract set_workflow_deterministic_value(workflow: pynenc.workflow.WorkflowIdentity, key: str, value: Any) None[source]¶
Store a deterministic value for a workflow.
- Parameters:
workflow_identity – Workflow identity
key – Value key
value – Value to store
- abstract store_app_info(app_info: pynenc.app.AppInfo) None[source]¶
Register this app’s information in the state backend for discovery.
- Parameters:
app_info – The app information to store
- Returns:
None
- abstract get_app_info() pynenc.app.AppInfo[source]¶
Retrieve information of the current app.
- Returns:
The app information
- abstract static get_all_app_infos() dict[str, pynenc.app.AppInfo][source]¶
Retrieve all app information registered in this state backend.
- Returns:
Dictionary mapping app_id to app information
- abstract store_workflow_run(workflow_identity: pynenc.workflow.WorkflowIdentity) None[source]¶
Store a workflow run for tracking and monitoring.
Maintains workflow type registry and specific workflow run instances. This enables monitoring of workflow types and their execution history.
- Parameters:
workflow_identity – The workflow identity to store
- abstract get_all_workflows() Iterator[str][source]¶
Retrieve all workflow types (workflow_task_ids) stored in this state backend.
- Returns:
Iterator of workflow task IDs representing different workflow types
- abstract get_all_workflows_runs() Iterator[pynenc.workflow.WorkflowIdentity][source]¶
Retrieve workflow run identities from this state backend.
- Returns:
Iterator of workflow identities for runs
- abstract get_workflow_runs(workflow_task_id: str) Iterator[pynenc.workflow.WorkflowIdentity][source]¶
Retrieve workflow run identities from this state backend.
- Parameters:
workflow_task_id – Filter for specific workflow type
- Returns:
Iterator of workflow identities for runs
- abstract store_workflow_sub_invocation(parent_workflow_id: str, sub_invocation_id: str) None[source]¶
Store a sub-invocation ID that runs inside a parent workflow.
This tracks which invocations (tasks or sub-workflows) are executed within the context of a parent workflow for monitoring and debugging.
- Parameters:
parent_workflow_id – The workflow ID that contains the sub-invocation
sub_invocation_id – The invocation ID of the task/sub-workflow running inside