Skip to main content

AuditWriter

Struct AuditWriter 

Source
pub struct AuditWriter { /* private fields */ }
Expand description

Caller-owned audit writer. Construction starts no workers, timers, or database operations.

Queued admission acknowledges memory only. Mandatory audit should use the DB store in the business transaction, or explicitly await flush and map failures at the product boundary. A failed or interrupted write remains available through unconfirmed; never replay an unknown commit without reconciling it first. Stop/join this writer before closing the database.

Implementations§

Source§

impl AuditWriter

Source

pub fn new(db: DatabaseConnection) -> Self

Uses default bounds and a bounded direct-overflow lane.

Source

pub fn with_config( db: DatabaseConnection, config: AuditLogBufferConfig, overflow: OverflowPolicy, events: Option<Sender<BufferedWriterEvent>>, ) -> Self

Configures overflow and optional bounded event delivery. Observer code is never invoked by this writer; a slow, panicking, or absent event consumer cannot block persistence.

Source

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

Starts the owned worker exactly once; normally called by the runtime component.

§Errors

Returns the current state when already started, draining, or stopped.

Source

pub async fn record( &self, request: AuditLogCreate, ) -> Result<RecordAdmission, RecordError<AuditLogCreate, DbError>>

Admits an audit record. Queued acknowledges memory only; DirectPersisted acknowledges just this overflow record. A cancelled direct waiter does not revoke accepted admission.

§Errors

Rejected records are returned. Direct failures retain the accepted record in this writer.

Source

pub fn begin_drain(&self)

Atomically closes admission while keeping accepted records available for drain. Call after all product producers and the server-shutdown audit hook have finished.

Source

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

Awaits persistence of records accepted before this future’s first poll, without closing admission. Batch and direct writes are acknowledged separately; later records and their failures do not extend this scope. An expired deadline schedules no new forced write, while an already acknowledged scope succeeds immediately, even with an expired deadline. Failed records stay in memory; cancelling this future leaves persistence owned by the worker.

§Errors

Returns lifecycle, original classified persistence, or deadline errors.

Source

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

Closes admission, attempts drain, then cancels and joins the worker before returning. Inspect remaining counts/failures before deciding product exit behavior. Repeated and concurrent calls are safe; database handles must remain open until this completes.

Source

pub fn retry_failed(&self)

Explicitly resumes only retry-safe failures; unknown commits and permanent failures stay blocked. Does not restart a stopped writer or silently replay retained records.

Source

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

Returns per-instance state, acknowledgment counters, and original classified failures.

Source

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

Copies unacknowledged records for product-controlled reconciliation. Stop the writer first for a stable recovery snapshot; these records must not be assumed absent from DB.

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

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
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