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.