pub struct SqlxIdempotencyStore { /* private fields */ }Implementations§
Source§impl SqlxIdempotencyStore
impl SqlxIdempotencyStore
pub fn new(pool: PgPool) -> Self
Sourcepub async fn ensure_schema(&self) -> Result<(), CoolError>
pub async fn ensure_schema(&self) -> Result<(), CoolError>
Ensure the table exists. Banks typically run this via their own migration tooling; exposed here for convenience.
Sourcepub async fn garbage_collect(&self) -> Result<u64, CoolError>
pub async fn garbage_collect(&self) -> Result<u64, CoolError>
Delete expired rows. Run periodically — the request path does
not auto-GC, although reserve_or_fetch does take over any
single expired row it tries to claim.
Trait Implementations§
Source§impl Clone for SqlxIdempotencyStore
impl Clone for SqlxIdempotencyStore
Source§fn clone(&self) -> SqlxIdempotencyStore
fn clone(&self) -> SqlxIdempotencyStore
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl IdempotencyStore for SqlxIdempotencyStore
impl IdempotencyStore for SqlxIdempotencyStore
Source§fn reserve_or_fetch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
principal: &'life1 str,
key: &'life2 str,
request_hash: [u8; 32],
expires_at: SystemTime,
) -> Pin<Box<dyn Future<Output = Result<ReservationOutcome, CoolError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn reserve_or_fetch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
principal: &'life1 str,
key: &'life2 str,
request_hash: [u8; 32],
expires_at: SystemTime,
) -> Pin<Box<dyn Future<Output = Result<ReservationOutcome, CoolError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Atomically reserve
(principal, key) for the caller, or report
the outcome of an existing reservation. Implementations MUST be
concurrent-safe: two simultaneous callers seeing the same key and
hash must observe exactly one Reserved and one InFlight,
never two Reserved. The expires_at argument bounds the
reservation’s lifetime so a forgotten release doesn’t pin the
key forever; when a retry reclaims an expired row the store
MUST rotate the reservation token so complete/release from
the original handler can no longer touch the newer slot.Source§fn complete<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
principal: &'life1 str,
key: &'life2 str,
token: Uuid,
status: u16,
headers: &'life3 [u8],
body: &'life4 [u8],
) -> Pin<Box<dyn Future<Output = Result<(), CoolError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
fn complete<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
principal: &'life1 str,
key: &'life2 str,
token: Uuid,
status: u16,
headers: &'life3 [u8],
body: &'life4 [u8],
) -> Pin<Box<dyn Future<Output = Result<(), CoolError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
Persist the captured response for a previously-reserved key so
subsequent attempts replay it. Banks treat the IETF idempotency
contract as “freeze the outcome”: if the handler returned 5xx,
retries see the same 5xx unless they use a fresh key. The
token must match the value returned by reserve_or_fetch
when this caller claimed the key; mismatched tokens are
silently no-ops so a stale handler whose reservation has been
reclaimed cannot overwrite a newer execution’s response. Read moreSource§fn release<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
principal: &'life1 str,
key: &'life2 str,
token: Uuid,
) -> Pin<Box<dyn Future<Output = Result<(), CoolError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn release<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
principal: &'life1 str,
key: &'life2 str,
token: Uuid,
) -> Pin<Box<dyn Future<Output = Result<(), CoolError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Release a reservation without recording a completion (e.g. the
inner service panicked or the middleware itself errored before
the response was ready). Subsequent attempts with the same key
can re-reserve. As with
complete, the token must match the
active reservation.Auto Trait Implementations§
impl Freeze for SqlxIdempotencyStore
impl !RefUnwindSafe for SqlxIdempotencyStore
impl Send for SqlxIdempotencyStore
impl Sync for SqlxIdempotencyStore
impl Unpin for SqlxIdempotencyStore
impl UnsafeUnpin for SqlxIdempotencyStore
impl !UnwindSafe for SqlxIdempotencyStore
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> 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> ⓘ
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