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 with sqlx pool defaults and run migrations.
Equivalent to Self::connect_with_options called with
PoolOptions::default(). Use that method instead when you need to
tune pool size or session-level timeouts.
§Errors
Returns an error if the connection or migration fails.
Sourcepub async fn connect_with_options(
url: &str,
options: PoolOptions,
) -> Result<Self, BackendError>
pub async fn connect_with_options( url: &str, options: PoolOptions, ) -> Result<Self, BackendError>
Connect to Postgres with explicit pool options and run migrations.
Field-level details on each option are documented on PoolOptions.
statement_timeout and idle_in_transaction_session_timeout are
installed via an after_connect hook that runs SET on every
freshly-acquired connection.
§Errors
Returns an error if the connection, the SET hooks, or the migration
fail.
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.
Prefer Self::connect_with_options when you only want to tune
standard pool knobs — this method is meant for callers who need full
control over the sqlx PgPool (custom TLS, listeners, etc.).
§Errors
Returns an error if the migration fails.
Trait Implementations§
Source§impl<C: Clone> Clone for PostgresBackend<C>
impl<C: Clone> Clone for PostgresBackend<C>
Source§fn clone(&self) -> PostgresBackend<C>
fn clone(&self) -> PostgresBackend<C>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<C> SignalStore for PostgresBackend<C>where
C: SnapshotCodec,
impl<C> SignalStore for PostgresBackend<C>where
C: SnapshotCodec,
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>
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>
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>
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>
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>
Source§async fn check_and_cancel(
&self,
instance_id: &str,
interrupted_at_task: Option<TaskId>,
) -> Result<bool, BackendError>
async fn check_and_cancel( &self, instance_id: &str, interrupted_at_task: Option<TaskId>, ) -> Result<bool, BackendError>
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>
Source§async fn unpause(
&self,
instance_id: &str,
) -> Result<WorkflowSnapshot, BackendError>
async fn unpause( &self, instance_id: &str, ) -> Result<WorkflowSnapshot, BackendError>
Source§impl<C> SnapshotStore for PostgresBackend<C>where
C: SnapshotCodec,
impl<C> SnapshotStore for PostgresBackend<C>where
C: SnapshotCodec,
Source§async fn save_snapshot(
&self,
snapshot: &mut WorkflowSnapshot,
) -> Result<(), BackendError>
async fn save_snapshot( &self, snapshot: &mut WorkflowSnapshot, ) -> Result<(), BackendError>
Source§async fn save_task_result(
&self,
instance_id: &str,
task_id: &TaskId,
output: Bytes,
) -> Result<(), BackendError>
async fn save_task_result( &self, instance_id: &str, task_id: &TaskId, output: Bytes, ) -> Result<(), BackendError>
Source§async fn load_snapshot(
&self,
instance_id: &str,
) -> Result<WorkflowSnapshot, BackendError>
async fn load_snapshot( &self, instance_id: &str, ) -> Result<WorkflowSnapshot, BackendError>
Source§async fn delete_snapshot(&self, instance_id: &str) -> Result<(), BackendError>
async fn delete_snapshot(&self, instance_id: &str) -> Result<(), BackendError>
Source§async fn list_snapshots(&self) -> Result<Vec<String>, BackendError>
async fn list_snapshots(&self) -> Result<Vec<String>, BackendError>
Source§impl<C> TaskClaimStore for PostgresBackend<C>where
C: SnapshotCodec,
impl<C> TaskClaimStore for PostgresBackend<C>where
C: SnapshotCodec,
Source§async fn claim_task(
&self,
instance_id: &str,
task_id: &TaskId,
worker_id: &str,
ttl: Option<Duration>,
) -> Result<Option<TaskClaim>, BackendError>
async fn claim_task( &self, instance_id: &str, task_id: &TaskId, worker_id: &str, ttl: Option<Duration>, ) -> Result<Option<TaskClaim>, BackendError>
Source§async fn release_task_claim(
&self,
instance_id: &str,
task_id: &TaskId,
worker_id: &str,
) -> Result<(), BackendError>
async fn release_task_claim( &self, instance_id: &str, task_id: &TaskId, worker_id: &str, ) -> Result<(), BackendError>
Source§async fn extend_task_claim(
&self,
instance_id: &str,
task_id: &TaskId,
worker_id: &str,
additional_duration: Duration,
) -> Result<(), BackendError>
async fn extend_task_claim( &self, instance_id: &str, task_id: &TaskId, worker_id: &str, additional_duration: Duration, ) -> Result<(), BackendError>
Source§async fn find_available_tasks(
&self,
worker_id: &str,
limit: usize,
aging_interval: Duration,
worker_tags: &[String],
) -> Result<Vec<AvailableTask>, BackendError>
async fn find_available_tasks( &self, worker_id: &str, limit: usize, aging_interval: Duration, worker_tags: &[String], ) -> Result<Vec<AvailableTask>, BackendError>
Source§async fn wait_for_wakeup(
&self,
timeout: Duration,
) -> Result<Option<TaskWakeupHint>, BackendError>
async fn wait_for_wakeup( &self, timeout: Duration, ) -> Result<Option<TaskWakeupHint>, BackendError>
timeout elapses. Some(hint)
when a producer attached one; None for hint-less wakeups,
timeout, or backends without a notification channel. Read moreSource§async fn find_hinted_task(
&self,
hint: &TaskWakeupHint,
) -> Result<Option<AvailableTask>, BackendError>
async fn find_hinted_task( &self, hint: &TaskWakeupHint, ) -> Result<Option<AvailableTask>, BackendError>
AvailableTask, or
None if the snapshot moved on / is claim-blocked / signal-blocked.
Does NOT claim — the caller runs the normal claim+execute pipeline.
Default returns None; backends opt in for the targeted lookup.Source§impl<C> TaskResultStore for PostgresBackend<C>where
C: SnapshotCodec,
impl<C> TaskResultStore for PostgresBackend<C>where
C: SnapshotCodec,
Source§async fn load_task_result(
&self,
instance_id: &str,
task_id: &TaskId,
) -> Result<Option<Bytes>, BackendError>
async fn load_task_result( &self, instance_id: &str, task_id: &TaskId, ) -> Result<Option<Bytes>, BackendError>
Auto Trait Implementations§
impl<C> !RefUnwindSafe for PostgresBackend<C>
impl<C> !UnwindSafe for PostgresBackend<C>
impl<C> Freeze for PostgresBackend<C>where
C: Freeze,
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,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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>
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