pynenc.state_backend.base_state_backend

Module Contents

Classes

InvocationHistory

Data structure representing the history of a task invocation.

BaseStateBackend

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.

invocation_id: str

None

_timestamp: datetime.datetime

‘field(…)’

status: Optional[pynenc.invocation.status.InvocationStatus]

None

execution_context: Optional[Any]

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.ABC

Abstract 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

conf() pynenc.conf.config_state_backend.ConfigStateBackend
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 purge() None[source]

Purges all store state backend data for the current application

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