Skip to main content

PostgresBackend

Struct PostgresBackend 

Source
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,

Source

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.

Source

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>

Source§

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>

Get the pending signal of the given kind, if any.
Source§

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>

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>

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>

Atomically check for cancellation and transition to cancelled state. Read more
Source§

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>

Transition a paused workflow back to in-progress and return the updated snapshot.
Source§

impl<C> SnapshotStore for PostgresBackend<C>

Source§

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>

Save a single task result atomically. Read more
Source§

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>

Delete a workflow snapshot.
Source§

async fn list_snapshots(&self) -> Result<Vec<String>, BackendError>

List all snapshot instance IDs.
Source§

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>

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>

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>

Extend a task claim’s expiration time.
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> PersistentBackend for T