Skip to main content

Outbox

Struct Outbox 

Source
pub struct Outbox<S: OutboxSink> { /* private fields */ }
Expand description

The handle callers stage through; owns the queue and its writer task.

Implementations§

Source§

impl<S: OutboxSink> Outbox<S>

Source

pub fn new(sink: S, concurrency: usize) -> Arc<Self> ⓘ

Creates the outbox around sink and starts its writer.

concurrency is the most tenants written at once, which bounds the connections the sink may hold.

§Panics

Panics when called outside a Tokio runtime, because the writer task is spawned immediately.

Source

pub fn sink(&self) -> &S

Borrows the sink this outbox writes through.

Source

pub fn stage(&self, tenant: DataTenantId, item: impl Into<S::Item>)

Queues one item for tenant without waiting and never fails.

The item is counted pending before it is sent, so the writer can never release it first. Once shutdown has begun, or if the writer is gone, the item never enters the queue; it is counted lost and logged instead.

Source

pub fn pending(&self) -> usize

Returns the number of items not yet written.

Source

pub async fn settle(&self, deadline: Instant) -> usize

Waits until deadline for everything staged so far to be written, without closing the outbox, and returns how many items remain.

The outbox keeps accepting items throughout; callers that read the sink’s destination right after staging use this to observe their items.

Source

pub async fn shutdown(&self, deadline: Instant) -> usize

Stops taking items, keeps writing and retrying until deadline, and returns how many items were lost at the deadline.

The staging sender is dropped before the first await, which is a one-way fence: everything staged before it drains, and every later Outbox::stage is refused and counted lost without entering the queue. Items still unwritten at the deadline are abandoned with the writer, which cancels any in-flight write; once the writer is gone they are counted in outbox_events_lost_total, logged, and released from pending() and outbox_pending, which both end at zero. When shutdown is called concurrently, exactly one caller reports the loss and the others report zero.

Trait Implementations§

Source§

impl<S> AuditStage for Outbox<S>
where S: OutboxSink, S::Item: From<AuditEvent>,

Source§

fn stage(&self, tenant: DataTenantId, event: AuditEvent)

Stages event on this outbox through its ordinary non-blocking Outbox::stage.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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

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