Skip to main content

ManagedBatchWriter

Struct ManagedBatchWriter 

Source
pub struct ManagedBatchWriter<T, E> { /* private fields */ }
Expand description

Explicitly started and stopped buffering with one owned worker and bounded overflow.

The sink must be cancellation-safe: interruption means an unknown commit, not a safe retry. T: Clone permits retaining originals while an owned copy is passed to persistence. Observers receive a bounded channel created by the caller; callbacks run outside persistence. No automatic retry occurs, including for Retryable failures.

Implementations§

Source§

impl<T: Clone + Send + 'static, E: Send + Sync + 'static> ManagedBatchWriter<T, E>

Source

pub fn new<F, Fut>( config: BufferedBatchConfig, overflow: OverflowPolicy, events: Option<Sender<BufferedWriterEvent>>, sink: F, ) -> Self
where F: Fn(Vec<T>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<(), WriteFailure<E>>> + Send + 'static,

Constructs an idle owner. Call start from the runtime startup phase.

Source

pub async fn start(&self) -> Result<(), BufferedWriterState>

Starts exactly once. Returns the current state if startup has already been attempted.

§Errors

Returns the current state unless this is the first start from Created.

Source

pub async fn record( &self, item: T, ) -> Result<RecordAdmission, RecordError<T, E>>

Admits a record or returns it when rejected. Cancellation of a direct waiter does not cancel its accepted record: the owned worker still persists or retains it.

§Errors

Rejection returns the record. A direct persistence failure retains it in the owner.

Source

pub fn begin_drain(&self)

Atomically stops admission. Accepted records remain owned and can still flush.

Source

pub async fn flush(&self, deadline: Instant) -> Result<(), BufferFlushError<E>>

Flushes records admitted before this future’s first poll, using a caller deadline. Later admissions cannot extend the captured scope or satisfy it through another lane. Dropping this future leaves accepted writes owned by the worker. A failed lane does not prevent draining other records in this scope. An expired deadline starts no new flush work. An already acknowledged scope succeeds even after the deadline. Normal threshold/timer writes and other flush callers proceed independently of this future’s scope and deadline.

§Errors

Returns a lifecycle error, the original in-scope write failure, or deadline exhaustion.

Source

pub fn retry_failed(&self)

Clears only failures classified as safe to retry. Unknown/permanent records stay blocked.

Source

pub async fn stop(&self, deadline: Instant) -> BufferStopReport<E>

Stops admission, drains until deadline/failure, then cancels and joins the owned worker. Repeated/concurrent calls share the same handle; cancelling a stop caller leaves the handle available for another caller. Dependencies must close only after this future returns.

Source

pub fn snapshot(&self) -> BufferedWriterSnapshot<E>

Captures independent state and counters, without invoking observer code.

Source

pub fn unconfirmed(&self) -> Vec<T>

Copies all unacknowledged records for reconciliation; never implicitly replays them. Stop first to obtain a stable recovery snapshot.

Trait Implementations§

Source§

impl<T, E> Drop for ManagedBatchWriter<T, E>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T, E> !Freeze for ManagedBatchWriter<T, E>

§

impl<T, E> !RefUnwindSafe for ManagedBatchWriter<T, E>

§

impl<T, E> Send for ManagedBatchWriter<T, E>
where T: Send, E: Sync + Send,

§

impl<T, E> Sync for ManagedBatchWriter<T, E>
where T: Send, E: Sync + Send,

§

impl<T, E> Unpin for ManagedBatchWriter<T, E>

§

impl<T, E> UnsafeUnpin for ManagedBatchWriter<T, E>

§

impl<T, E> !UnwindSafe for ManagedBatchWriter<T, E>

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.

§

impl<T> Instrument for T

§

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

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

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

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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