Skip to main content

SpooledClient

Struct SpooledClient 

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

A durable-emit wrapper around a crate::Client.

Holds the client, the spool path, and an in-process Mutex that serializes every spool-file operation (single-producer-per-spool-file).

Implementations§

Source§

impl SpooledClient

Source

pub fn new(client: Client, spool_path: PathBuf) -> SpooledClient

Build an unbounded durable-emit client over client, buffering to spool_path. Use with_config to opt into a retention cap.

Source

pub fn with_config(client: Client, config: SpoolConfig) -> SpooledClient

Build from a SpoolConfig, carrying its retention caps.

Source

pub fn client(&self) -> &Client

Borrow the underlying client for reads / non-spooled ops (retrieve, health, pin, capsules, …). Only append_observation is durability-wrapped.

Source

pub async fn append_observation( &self, input: ObservationInput, capsule_id: Option<String>, validate: Option<bool>, ) -> Result<AppendOutcome, SpoolError>

Append an observation durably.

Assigns a stable v4 id when input.id is None (so a spooled entry and any replay share one id — see the crate-level Delivery semantics). Then:

  1. If the spool already has buffered entries, opportunistically flush them first so the daemon observes them in append order ahead of this new one.
  2. Try the daemon. On success → AppendOutcome::Delivered.
  3. On a connectivity failure (Unavailable / Http) → buffer to the spool and return AppendOutcome::Spooled (never an error).
  4. On any other client error → propagate as SpoolError::Client; the observation is not spooled.
Source

pub async fn flush(&self) -> Result<FlushReport, SpoolError>

Drain the spool into the daemon, in order.

Replays each buffered entry via the client. Stops at the first connectivity failure (Unavailable / Http), keeping that entry and the remainder. A non-connectivity client error also stops the drain and is propagated, but the un-replayed remainder (including the rejected entry) is preserved — data is never silently dropped.

The spool file is rewritten with exactly the un-replayed remainder via a temp-file-then-rename, so a crash mid-flush cannot corrupt the spool.

If a retention cap is configured (see SpoolConfig), the retained remainder is trimmed (oldest first) before the rewrite — see the crate-level Retention docs. This is the only place trimming happens, so it can never race a concurrent drain.

Source

pub fn pending_count(&self) -> Result<usize, SpoolError>

Count of pending (un-replayed) spool entries.

Source

pub async fn spool_status(&self) -> Result<SpoolStatus, SpoolError>

Observability snapshot for this client (pending count + live counters).

Source

pub fn spool_status_from_path( spool_path: impl Into<PathBuf>, ) -> Result<SpoolStatus, SpoolError>

Passive status from an on-disk spool file and its optional .status.json sidecar (best-effort: a corrupt sidecar is ignored).

Trait Implementations§

Source§

impl Debug for SpooledClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

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.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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