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>
impl<S: OutboxSink> Outbox<S>
Sourcepub fn new(sink: S, concurrency: usize) -> Arc<Self> ⓘ
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.
Sourcepub fn stage(&self, tenant: DataTenantId, item: impl Into<S::Item>)
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.
Sourcepub async fn settle(&self, deadline: Instant) -> usize
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.
Sourcepub async fn shutdown(&self, deadline: Instant) -> usize
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>
impl<S> AuditStage for Outbox<S>
Source§fn stage(&self, tenant: DataTenantId, event: AuditEvent)
fn stage(&self, tenant: DataTenantId, event: AuditEvent)
Stages event on this outbox through its ordinary non-blocking
Outbox::stage.