Skip to main content

PostgresInboxStore

Struct PostgresInboxStore 

Source
#[non_exhaustive]
pub struct PostgresInboxStore { /* private fields */ }
Expand description

Reliar’s PostgreSQL inbox provider (inbox contract §3). A separate type from crate::PostgresOutboxStore: the inbox stores no payload, so it needs no Serializer type parameter and none of the outbox’s lease/ordering/retention settings. Same crate, same schema, same crate::migrate. Cheap to clone — wraps a PgPool; no outer Arc required.

Implementations§

Source§

impl PostgresInboxStore

Source

pub async fn connect( pool: PgPool, settings: PostgresInboxSettings, ) -> Result<Self, PostgresInboxError>

Verifies the server version (ADR 0041) and then the search_path (ADR 0018/§20.1), in that order — exactly as crate::PostgresOutboxStore::connect does: a wrong server version explains a missing relation, and the reverse is never true. Logs a tracing::warn! when a same-named table also exists in another schema on the path.

§Errors

Returns PostgresInboxError::UnsupportedServerVersion, PostgresInboxError::NotMigrated (the relation itself is missing), PostgresInboxError::SchemaNotOnSearchPath (it exists, but not on the configured schema), or PostgresInboxError::Database for a connection failure during verification.

use reliar_store_postgres::{PostgresInboxSettings, PostgresInboxStore};
use sqlx::postgres::PgPoolOptions;

let pool = PgPoolOptions::new()
    .connect(&std::env::var("DATABASE_URL")?)
    .await?;
let store = PostgresInboxStore::connect(pool, PostgresInboxSettings::default()).await?;

Trait Implementations§

Source§

impl Clone for PostgresInboxStore

Source§

fn clone(&self) -> PostgresInboxStore

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PostgresInboxStore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl InboxDeadLetters for PostgresInboxStore

Source§

fn list_dead( &self, query: InboxDeadQuery, ) -> impl Future<Output = Result<Vec<InboxRecord>, Self::Error>> + Send

ORDER BY dead_at, id is normative: database-authored death time is the keyset’s leading column, and the unique row id breaks ties.

Source§

type Error = PostgresInboxError

A failure of the call.
Source§

fn retry_dead( &self, ids: &[InboxRecordId], ) -> impl Future<Output = Result<u64, Self::Error>> + Send

Clears dead_at, resets attempts to 0, keeps last_error for audit, sets updated_at = now(). Affects only rows with dead_at IS NOT NULL. Returns the number of rows affected. Read more
Source§

fn purge_dead( &self, ids: &[InboxRecordId], ) -> impl Future<Output = Result<u64, Self::Error>> + Send

Deletes dead rows by id, regardless of retention. Returns the number of rows affected. Read more
Source§

impl<'c> InboxStore<Transaction<'c, Postgres>> for PostgresInboxStore

Source§

fn claim( &self, tx: &mut Transaction<'c, Postgres>, scope: &InboxScope, message: InboxMessage<'_>, ) -> impl Future<Output = Result<InboxClaim, Self::Error>> + Send

The three-statement claim (inbox contract §3.1): the in-flight advisory-lock guard, the INSERT … ON CONFLICT DO NOTHING claim, and — only when nothing was inserted — the state read that decides AlreadyCompleted/Dead vs. Claimed.

Source§

fn complete( &self, tx: &mut Transaction<'c, Postgres>, scope: &InboxScope, id: MessageId, ) -> impl Future<Output = Result<(), Self::Error>> + Send

Marks the row completed in the caller’s transaction. Zero rows affected ⇒ NotClaimed (including a row that has since gone dead — the guard is completed_at IS NULL AND dead_at IS NULL).

Source§

fn fail( &self, scope: &InboxScope, message: InboxMessage<'_>, error: &(dyn Error + 'static), ) -> impl Future<Output = Result<InboxFailure, Self::Error>> + Send

Records a failed attempt on this store’s own pool, guarded by completed_at IS NULL, and bounds it at settings.max_attempts atomically with the increment (ADR 0042 A.2.4).

Source§

async fn find( &self, scope: &InboxScope, id: MessageId, ) -> Result<Option<InboxRecord>, Self::Error>

Reads a row for diagnostics. No Reliar code path calls it. No span — the inbox contract’s observability table (§4) does not list find, since no Reliar code path calls it.

Source§

fn purge( &self, request: InboxPurgeRequest, ) -> impl Future<Output = Result<InboxPurgeReport, Self::Error>> + Send

One bounded pass, three statements, each capped at request.batch_size: the completed-row, incomplete-row and dead-row deletes.

Source§

type Error = PostgresInboxError

What inbox operations fail with. Classify so a caller can log a permanent failure differently from a transient one without a downcast.
Source§

fn process<H>( &self, tx: &mut Tx, scope: &InboxScope, message: InboxMessage<'_>, handler: &H, ) -> impl Future<Output = Result<InboxOutcome<<H as InboxHandler<Tx>>::Output>, InboxProcessError<Self::Error, <H as InboxHandler<Tx>>::Error>>> + Send
where H: InboxHandler<Tx> + Sync, Tx: Send,

The happy path in one call: claim, branch, run handler, complete. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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