On this page
Subscription and event-source CRUD: subscribe()/unsubscribe() manage principal-owned dispatch subscriptions and their action chains; create_source() and friends register and manage event sources.
#services.src.orxtra.services._dispatch
#services.src.orxtra.services._dispatch
#_resolve_action_from_dict
def _resolve_action_from_dict(action_data: dict[str, Any]) -> ActionResolve a plain dict to a typed Action instance.
Detects the action type from dict keys and validates via pydantic.
#subscribe
async def subscribe(backend: DispatchBackend, caller_principal: Principal, filter_pred: FilterPredicate, actions: list[dict[str, Any]], *, storage: str='persistent') -> UUIDCreate a subscription with actions, owned by the calling principal.
Thin wrapper: builds a Subscription from the filter predicate, attributing ownership to caller_principal (the authenticated actor derived at the dispatch choke point), persists it via the backend, then creates SubscriptionActions for each action dict in order. Action dicts are resolved to typed Action instances before storage.
A subscription is operational state owned by its principal: the FK CASCADEs, so deleting the owner deletes the subscription.
#unsubscribe
async def unsubscribe(backend: DispatchBackend, subscription_id: UUID) -> NoneDisable and delete a subscription and its actions.
#list_subscriptions
async def list_subscriptions(backend: DispatchBackend, *, enabled_only: bool=True, principal_id: UUID | None=None) -> list[Subscription]List subscriptions, optionally filtering to enabled-only and by owner.
#create_source
async def create_source(pool: asyncpg.Pool | None, backend: DispatchBackend, principal_storage: PrincipalStorage, caller_principal: Principal, slug: str, name: str, *, credential_id: UUID | None=None, config: dict[str, Any] | None=None) -> UUIDCreate a new event source, minting the source's identity at birth.
Flow, mirroring the runs vertical:
- If a
credential_idis supplied, validate it exists against auth's
credentials table via pool -- an unknown id is a hard error. This closes the honor-system gap where a source could reference a non-existent credential. Reading auth's tables is legal: the single-writer rule bars writes to another module's tables, not reads.
- Generate the source id client-side so the source's principal can exist
before the row that FKs into it.
- Mint the source principal (kind=source, external_ref=source id,
display_name=slug).
- Persist the source attributed to the caller (
created_by).
#get_source
async def get_source(backend: DispatchBackend, source_id: UUID) -> Source | NoneGet a source by ID, or None if not found.
#get_source_by_slug
async def get_source_by_slug(backend: DispatchBackend, slug: str) -> Source | NoneGet a source by slug, or None if not found.
#list_sources
async def list_sources(backend: DispatchBackend) -> list[Source]List all registered sources.
#delete_source
async def delete_source(backend: DispatchBackend, source_id: UUID) -> NoneDelete a source by ID.