Actions¶
Register and execute actions (on_enter, on_exit, transition actions).
ActionRegistry
¶
Registry for action functions (sync and async).
Example
registry = ActionRegistry() registry.register("notify", lambda ctx: print("notified")) registry.execute("notify", {"user": "alice"})
Source code in src/pystator/actions.py
register
¶
Register an action function. Thread-safe.
Source code in src/pystator/actions.py
unregister
¶
Unregister an action function. Thread-safe.
Source code in src/pystator/actions.py
get_metadata
¶
decorator
¶
decorator(
name: str | None = None,
metadata: dict[str, Any] | None = None,
) -> Callable[[AnyActionFunc], AnyActionFunc]
Decorator to register an action function.
Example
@registry.decorator() ... def notify_user(ctx: dict) -> None: ... send_email(ctx["user_email"], "Order updated")
Source code in src/pystator/actions.py
ActionExecutor
¶
ActionExecutor(
registry: ActionRegistry,
stop_on_error: bool = False,
log_execution: bool = True,
default_mode: ExecutionMode = ExecutionMode.SEQUENTIAL,
strict: bool = False,
)
Executes actions from transition results.
Supports sequential, parallel, and phased execution modes.
Example
executor = ActionExecutor(action_registry) execution = executor.execute(transition_result, context)
Source code in src/pystator/actions.py
execute
¶
Execute all actions from a transition result sequentially.
Source code in src/pystator/actions.py
execute_specific
¶
execute_specific(
action_names: list[str] | tuple[str, ...],
context: dict[str, Any],
) -> list[ActionResult]
Execute specific actions by name sequentially.
Source code in src/pystator/actions.py
validate_actions_exist
¶
Return list of action names that are not registered.
Source code in src/pystator/actions.py
async_execute
async
¶
Execute all actions asynchronously in sequential order.
Source code in src/pystator/actions.py
async_execute_parallel
async
¶
async_execute_parallel(
transition_result: TransitionResult,
context: dict[str, Any],
) -> ExecutionResult
Execute all actions concurrently using asyncio.gather.
Source code in src/pystator/actions.py
async_execute_phased
async
¶
async_execute_phased(
transition_result: TransitionResult,
context: dict[str, Any],
) -> ExecutionResult
Execute actions in phases: exit -> transition -> enter (each parallel).
Source code in src/pystator/actions.py
async_execute_with_mode
async
¶
async_execute_with_mode(
transition_result: TransitionResult,
context: dict[str, Any],
mode: ExecutionMode = ExecutionMode.SEQUENTIAL,
) -> ExecutionResult
Execute with explicit mode (sequential, parallel, or phased).
Source code in src/pystator/actions.py
async_execute_specific_parallel
async
¶
async_execute_specific_parallel(
action_names: list[str] | tuple[str, ...],
context: dict[str, Any],
) -> list[ActionResult]
Execute specific actions in parallel by name.
Source code in src/pystator/actions.py
async_execute_action_spec
async
¶
Async execute a single ActionSpec.
Source code in src/pystator/actions.py
async_execute_action_specs_parallel
async
¶
async_execute_action_specs_parallel(
actions: tuple[ActionSpec, ...] | list[ActionSpec],
context: dict[str, Any],
) -> list[ActionResult]
Async execute multiple ActionSpecs in parallel.