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
impl AuditWriter
Sourcepub fn new(db: DatabaseConnection) -> Self
pub fn new(db: DatabaseConnection) -> Self
Uses default bounds and a bounded direct-overflow lane.
Sourcepub fn with_config(
db: DatabaseConnection,
config: AuditLogBufferConfig,
overflow: OverflowPolicy,
events: Option<Sender<BufferedWriterEvent>>,
) -> Self
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.
Sourcepub async fn start(&self) -> Result<(), BufferedWriterState>
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.
Sourcepub async fn record(
&self,
request: AuditLogCreate,
) -> Result<RecordAdmission, RecordError<AuditLogCreate, DbError>>
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.
Sourcepub fn begin_drain(&self)
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.
Sourcepub async fn flush(
&self,
deadline: Instant,
) -> Result<(), BufferFlushError<DbError>>
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.
Sourcepub async fn stop(&self, deadline: Instant) -> BufferStopReport<DbError>
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.
Sourcepub fn retry_failed(&self)
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.
Sourcepub fn snapshot(&self) -> BufferedWriterSnapshot<DbError>
pub fn snapshot(&self) -> BufferedWriterSnapshot<DbError>
Returns per-instance state, acknowledgment counters, and original classified failures.
Sourcepub fn unconfirmed(&self) -> Vec<AuditLogCreate>
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§
impl !Freeze for AuditWriter
impl !RefUnwindSafe for AuditWriter
impl Send for AuditWriter
impl Sync for AuditWriter
impl Unpin for AuditWriter
impl UnsafeUnpin for AuditWriter
impl !UnwindSafe for AuditWriter
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
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>
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