pub struct PostgresBackend<C> { /* private fields */ }Expand description
PostgreSQL persistence backend for Sayiir workflows.
Generic over a Codec that determines how
snapshots are serialized into the BYTEA column. Use JsonCodec for
human-readable storage with Postgres-side queryability, or a binary codec
for faster (de)serialization.
§Example (with sayiir-runtime JSON codec)
use sayiir_postgres::PostgresBackend;
use sayiir_runtime::serialization::JsonCodec;
let backend = PostgresBackend::<JsonCodec>::connect("postgresql://localhost/sayiir").await?;Implementations§
Source§impl<C> PostgresBackend<C>where
C: Default,
impl<C> PostgresBackend<C>where
C: Default,
Sourcepub async fn connect(url: &str) -> Result<Self, BackendError>
pub async fn connect(url: &str) -> Result<Self, BackendError>
Connect to Postgres and run migrations.
§Errors
Returns an error if the connection or migration fails.
Sourcepub async fn connect_with(pool: PgPool) -> Result<Self, BackendError>
pub async fn connect_with(pool: PgPool) -> Result<Self, BackendError>
Use an existing connection pool and run migrations.
§Errors
Returns an error if the migration fails.
Trait Implementations§
Source§impl<C> SignalStore for PostgresBackend<C>
impl<C> SignalStore for PostgresBackend<C>
Source§async fn store_signal(
&self,
instance_id: &str,
kind: SignalKind,
request: SignalRequest,
) -> Result<(), BackendError>
async fn store_signal( &self, instance_id: &str, kind: SignalKind, request: SignalRequest, ) -> Result<(), BackendError>
Store a signal (cancel or pause) for a workflow instance.
Source§async fn get_signal(
&self,
instance_id: &str,
kind: SignalKind,
) -> Result<Option<SignalRequest>, BackendError>
async fn get_signal( &self, instance_id: &str, kind: SignalKind, ) -> Result<Option<SignalRequest>, BackendError>
Get the pending signal of the given kind, if any.
Source§async fn clear_signal(
&self,
instance_id: &str,
kind: SignalKind,
) -> Result<(), BackendError>
async fn clear_signal( &self, instance_id: &str, kind: SignalKind, ) -> Result<(), BackendError>
Clear the signal of the given kind.
Source§async fn send_event(
&self,
instance_id: &str,
signal_name: &str,
payload: Bytes,
) -> Result<(), BackendError>
async fn send_event( &self, instance_id: &str, signal_name: &str, payload: Bytes, ) -> Result<(), BackendError>
Send an external event to a workflow instance. Read more
Source§async fn consume_event(
&self,
instance_id: &str,
signal_name: &str,
) -> Result<Option<Bytes>, BackendError>
async fn consume_event( &self, instance_id: &str, signal_name: &str, ) -> Result<Option<Bytes>, BackendError>
Consume the oldest buffered event for the given signal name, if any. Read more
Source§async fn check_and_cancel(
&self,
instance_id: &str,
interrupted_at_task: Option<&str>,
) -> Result<bool, BackendError>
async fn check_and_cancel( &self, instance_id: &str, interrupted_at_task: Option<&str>, ) -> Result<bool, BackendError>
Atomically check for cancellation and transition to cancelled state. Read more
Source§async fn check_and_pause(&self, instance_id: &str) -> Result<bool, BackendError>
async fn check_and_pause(&self, instance_id: &str) -> Result<bool, BackendError>
Atomically check for a pause request and transition to paused state. Read more
Source§async fn unpause(
&self,
instance_id: &str,
) -> Result<WorkflowSnapshot, BackendError>
async fn unpause( &self, instance_id: &str, ) -> Result<WorkflowSnapshot, BackendError>
Transition a paused workflow back to in-progress and return the updated snapshot.
Source§impl<C> SnapshotStore for PostgresBackend<C>
impl<C> SnapshotStore for PostgresBackend<C>
Source§async fn save_snapshot(
&self,
snapshot: &WorkflowSnapshot,
) -> Result<(), BackendError>
async fn save_snapshot( &self, snapshot: &WorkflowSnapshot, ) -> Result<(), BackendError>
Save a workflow snapshot. Read more
Source§async fn save_task_result(
&self,
instance_id: &str,
task_id: &str,
output: Bytes,
) -> Result<(), BackendError>
async fn save_task_result( &self, instance_id: &str, task_id: &str, output: Bytes, ) -> Result<(), BackendError>
Save a single task result atomically. Read more
Source§async fn load_snapshot(
&self,
instance_id: &str,
) -> Result<WorkflowSnapshot, BackendError>
async fn load_snapshot( &self, instance_id: &str, ) -> Result<WorkflowSnapshot, BackendError>
Load a workflow snapshot by instance ID.
Source§async fn delete_snapshot(&self, instance_id: &str) -> Result<(), BackendError>
async fn delete_snapshot(&self, instance_id: &str) -> Result<(), BackendError>
Delete a workflow snapshot.
Source§async fn list_snapshots(&self) -> Result<Vec<String>, BackendError>
async fn list_snapshots(&self) -> Result<Vec<String>, BackendError>
List all snapshot instance IDs.
Source§impl<C> TaskClaimStore for PostgresBackend<C>
impl<C> TaskClaimStore for PostgresBackend<C>
Source§async fn claim_task(
&self,
instance_id: &str,
task_id: &str,
worker_id: &str,
ttl: Option<Duration>,
) -> Result<Option<TaskClaim>, BackendError>
async fn claim_task( &self, instance_id: &str, task_id: &str, worker_id: &str, ttl: Option<Duration>, ) -> Result<Option<TaskClaim>, BackendError>
Claim a task for execution by a worker node. Read more
Source§async fn release_task_claim(
&self,
instance_id: &str,
task_id: &str,
worker_id: &str,
) -> Result<(), BackendError>
async fn release_task_claim( &self, instance_id: &str, task_id: &str, worker_id: &str, ) -> Result<(), BackendError>
Release a task claim.
Source§async fn extend_task_claim(
&self,
instance_id: &str,
task_id: &str,
worker_id: &str,
additional_duration: Duration,
) -> Result<(), BackendError>
async fn extend_task_claim( &self, instance_id: &str, task_id: &str, worker_id: &str, additional_duration: Duration, ) -> Result<(), BackendError>
Extend a task claim’s expiration time.
Source§async fn find_available_tasks(
&self,
worker_id: &str,
limit: usize,
) -> Result<Vec<AvailableTask>, BackendError>
async fn find_available_tasks( &self, worker_id: &str, limit: usize, ) -> Result<Vec<AvailableTask>, BackendError>
Find available tasks across all workflow instances.
Auto Trait Implementations§
impl<C> Freeze for PostgresBackend<C>where
C: Freeze,
impl<C> !RefUnwindSafe for PostgresBackend<C>
impl<C> Send for PostgresBackend<C>where
C: Send,
impl<C> Sync for PostgresBackend<C>where
C: Sync,
impl<C> Unpin for PostgresBackend<C>where
C: Unpin,
impl<C> UnsafeUnpin for PostgresBackend<C>where
C: UnsafeUnpin,
impl<C> !UnwindSafe for PostgresBackend<C>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more