"""Persistence protocol shared by embedded and production Run stores."""
from __future__ import annotations
from collections.abc import Mapping
from datetime import datetime
from typing import Protocol, runtime_checkable
from uuid import UUID
from rath.runtime.models import (
ApprovalDecision,
Checkpoint,
ClaimedRun,
Interrupt,
ResourceLease,
Run,
RunEvent,
RunStatus,
)
__all__ = ["RunStore"]
[docs]
@runtime_checkable
class RunStore(Protocol):
[docs]
def create_run(self, run: Run) -> Run: ...
[docs]
def get_run(self, run_id: UUID) -> Run: ...
self,
*,
tenant_id: str,
after: UUID | None = None,
limit: int | None = None,
session_id: UUID | None = None,
statuses: tuple[RunStatus, ...] | None = None,
) -> tuple[Run, ...]: ...
self,
*,
status: RunStatus,
tenant_id: str | None = None,
) -> int: ...
self,
run_id: UUID,
*,
expected_version: int,
target: RunStatus,
state: Mapping[str, object] | None = None,
next_nodes: tuple[str, ...] | None = None,
) -> Run: ...
self,
run_id: UUID,
*,
after_sequence: int = 0,
limit: int | None = None,
) -> tuple[RunEvent, ...]: ...
self,
run_id: UUID,
type: str,
data: Mapping[str, object],
) -> RunEvent: ...
[docs]
def append_checkpoint(self, checkpoint: Checkpoint) -> None: ...
[docs]
def latest_checkpoint(self, run_id: UUID) -> Checkpoint | None: ...
[docs]
def list_checkpoints(self, run_id: UUID) -> tuple[Checkpoint, ...]: ...
self,
checkpoint: Checkpoint,
*,
worker_id: str,
fencing_token: int,
expected_run_version: int,
) -> Run: ...
self,
interrupt: Interrupt,
*,
expected_run_version: int,
) -> Run: ...
[docs]
def get_interrupt(self, interrupt_id: UUID) -> Interrupt: ...
self,
*,
tenant_id: str,
pending_only: bool = True,
) -> tuple[Interrupt, ...]: ...
self,
*,
now: datetime | None = None,
) -> tuple[UUID, ...]: ...
self,
interrupt_id: UUID,
*,
decision: ApprovalDecision,
expected_run_version: int,
) -> Run: ...
self,
*,
worker_id: str,
lease_seconds: float,
now: datetime | None = None,
) -> ClaimedRun | None: ...
self,
run_id: UUID,
*,
worker_id: str,
fencing_token: int,
lease_seconds: float,
now: datetime | None = None,
) -> ResourceLease: ...
[docs]
def assert_fencing_token(
self,
run_id: UUID,
*,
worker_id: str,
fencing_token: int,
) -> None: ...
[docs]
def requeue_expired_leases(
self,
*,
now: datetime | None = None,
) -> tuple[UUID, ...]: ...
self,
run_id: UUID,
*,
worker_id: str,
fencing_token: int,
expected_run_version: int,
target: RunStatus,
event_type: str = "run.execution.completed",
event_data: Mapping[str, object] | None = None,
) -> Run: ...
[docs]
def close(self) -> None: ...