pynenc.invocation.status¶
Invocation status management.
This module defines the status lifecycle of task invocations, including state transitions, ownership rules, and the state machine that enforces them.
Key components:
InvocationStatus: Enum of all possible invocation states
InvocationStatusRecord: Immutable record combining status with ownership
StatusDefinition: Declarative rules for status behavior
State machine functions: Validation and transition logic
Module Contents¶
Classes¶
An enumeration representing the status of a task invocation. |
|
Immutable record combining status with ownership information. |
|
Declarative definition of status behavior and ownership rules. |
|
Complete configuration for invocation status behavior. |
Functions¶
Get the status definition for a given invocation status. |
|
Validate state transition or raise exception. |
|
Validate ownership requirements for a transition. |
|
Compute new owner based on status transition. |
|
Execute a status change with safety checks. |
Data¶
API¶
- class pynenc.invocation.status.InvocationStatus[source]¶
Bases:
enum.StrEnumAn enumeration representing the status of a task invocation.
The PENDING status will expire after the time specified in
- Attr:
~pynenc.conf.config_pynenc.ConfigPynenc.max_pending_seconds.
Note
FAILED, RETRY, and SUCCESS are final statuses that terminate the invocation lifecycle.
- Variables:
REGISTERED – The task call has been routed and is registered
CONCURRENCY_CONTROLLED – The task call is not allowed to run due to concurrency control
CONCURRENCY_CONTROLLED_FINAL – The task call was blocked by concurrency control and will not be retried
REROUTED – The task call has been re-routed and is registered
PENDING – The task call was picked by a runner but is not yet executed
PENDING_RECOVERY – The task call exceeded PENDING timeout and is being recovered
RUNNING – The task call is currently running
RUNNING_RECOVERY – The task call is being recovered because the owner runner is inactive
PAUSED – The task call execution is paused
RESUMED – The task call execution has been resumed
KILLED – The task call execution has been killed
SUCCESS – The task call finished without errors
FAILED – The task call finished with exceptions
RETRY – The task call finished with a retriable exception
Initialization
Initialize self. See help(type(self)) for accurate signature.
- REGISTERED¶
‘auto(…)’
- CONCURRENCY_CONTROLLED¶
‘auto(…)’
- CONCURRENCY_CONTROLLED_FINAL¶
‘auto(…)’
- REROUTED¶
‘auto(…)’
- PENDING¶
‘auto(…)’
- PENDING_RECOVERY¶
‘auto(…)’
- RUNNING¶
‘auto(…)’
- RUNNING_RECOVERY¶
‘auto(…)’
- PAUSED¶
‘auto(…)’
- RESUMED¶
‘auto(…)’
- KILLED¶
‘auto(…)’
- SUCCESS¶
‘auto(…)’
- FAILED¶
‘auto(…)’
- RETRY¶
‘auto(…)’
- can_transition_to(target: pynenc.invocation.status.InvocationStatus) bool[source]¶
Check if this status has a valid transition to the target status.
- classmethod get_final_statuses() frozenset[pynenc.invocation.status.InvocationStatus][source]¶
Return all statuses that terminate the invocation lifecycle.
- classmethod get_available_for_run_statuses() frozenset[pynenc.invocation.status.InvocationStatus][source]¶
Return all statuses where invocations can be picked up by runners.
- class pynenc.invocation.status.InvocationStatusRecord[source]¶
Immutable record combining status with ownership information.
- Variables:
status (InvocationStatus) – The current invocation status
runner_id (str | None) – Runner ID that owns this invocation (None if no owner)
timestamp (datetime) – When this status was set
- status: pynenc.invocation.status.InvocationStatus¶
None
- timestamp: datetime.datetime¶
‘field(…)’
- classmethod from_json(json_dict: dict) pynenc.invocation.status.InvocationStatusRecord[source]¶
Deserialize a JSON-compatible dictionary into a status record.
- class pynenc.invocation.status.StatusDefinition[source]¶
Declarative definition of status behavior and ownership rules.
- Variables:
allowed_transitions (frozenset[InvocationStatus]) – Valid next statuses
is_final (bool) – Terminates invocation lifecycle
available_for_run (bool) – Can be picked up by runners
requires_ownership (bool) – Only owner can modify
acquires_ownership (bool) – Claims ownership on entry
releases_ownership (bool) – Releases ownership on entry
overrides_ownership (bool) – Bypasses ownership validation (for recovery scenarios)
- allowed_transitions: frozenset[pynenc.invocation.status.InvocationStatus]¶
‘field(…)’
- class pynenc.invocation.status.StatusConfiguration[source]¶
Complete configuration for invocation status behavior.
- Variables:
definitions (dict[InvocationStatus | None, StatusDefinition]) – Behavior rules per status
- definitions: dict[pynenc.invocation.status.InvocationStatus | None, pynenc.invocation.status.StatusDefinition]¶
None
- final_statuses() frozenset[pynenc.invocation.status.InvocationStatus]¶
- available_for_run_statuses() frozenset[pynenc.invocation.status.InvocationStatus]¶
- ownership_required_statuses() frozenset[pynenc.invocation.status.InvocationStatus]¶
- ownership_acquire_statuses() frozenset[pynenc.invocation.status.InvocationStatus]¶
- ownership_release_statuses() frozenset[pynenc.invocation.status.InvocationStatus]¶
- get_definition(status: pynenc.invocation.status.InvocationStatus | None) pynenc.invocation.status.StatusDefinition[source]¶
- pynenc.invocation.status._CONFIG: Final[pynenc.invocation.status.StatusConfiguration]¶
‘StatusConfiguration(…)’
- pynenc.invocation.status.get_status_definition(status: pynenc.invocation.status.InvocationStatus) pynenc.invocation.status.StatusDefinition[source]¶
Get the status definition for a given invocation status.
- Parameters:
status – The invocation status to look up
- Returns:
The status definition with rules and behavior
- pynenc.invocation.status.validate_transition(from_status: pynenc.invocation.status.InvocationStatus | None, to_status: pynenc.invocation.status.InvocationStatus) None[source]¶
Validate state transition or raise exception.
- Parameters:
from_status (InvocationStatus | None) – Current status (None for new invocations)
to_status (InvocationStatus) – Target status
- Raises:
InvocationStatusTransitionError – If transition is invalid
- pynenc.invocation.status.validate_ownership(current_record: pynenc.invocation.status.InvocationStatusRecord | None, new_status: pynenc.invocation.status.InvocationStatus, runner_id: str | None) None[source]¶
Validate ownership requirements for a transition.
- Parameters:
current_record (InvocationStatusRecord | None) – Current status record
new_status (InvocationStatus) – Target status
runner_id (str | None) – Runner attempting the transition
- Raises:
InvocationStatusOwnershipError – If ownership rules are violated
- pynenc.invocation.status.compute_new_owner(current_record: pynenc.invocation.status.InvocationStatusRecord | None, new_status: pynenc.invocation.status.InvocationStatus, runner_id: str | None) str | None[source]¶
Compute new owner based on status transition.
- pynenc.invocation.status.status_record_transition(current_record: pynenc.invocation.status.InvocationStatusRecord | None, new_status: pynenc.invocation.status.InvocationStatus, runner_id: str | None) pynenc.invocation.status.InvocationStatusRecord[source]¶
Execute a status change with safety checks.
- Parameters:
current_record (InvocationStatusRecord | None) – Current state (None for new invocations)
new_status (InvocationStatus) – Desired new status
runner_id (str | None) – ID of runner making the change
- Returns:
New validated status record
- Raises:
InvocationStatusTransitionError – If transition is not allowed
InvocationStatusOwnershipError – If ownership rules are violated