ppoppo-infra 0.1.0

Backend-agnostic infrastructure traits for caching, queuing, and messaging
Documentation
//! Backend-agnostic staging writer trait.
//!
//! Synchronous enqueue (mpsc channel push) — zero DB, zero async.
//! Backend-specific flush: PG uses UNNEST INSERT, KVrocks uses XADD.

use crate::Result;

/// High-throughput staging writer.
///
/// `enqueue()` is synchronous (mpsc push) — no async, no DB.
/// A background task handles batch flushing to the backend.
pub trait StagingWriter: Send + Sync {
    /// Enqueue a single item. Returns a generated ID immediately.
    fn enqueue(&self, queue_name: &str, payload: &serde_json::Value) -> Result<String>;

    /// Enqueue multiple items. Returns generated IDs immediately.
    fn enqueue_batch(
        &self,
        queue_name: &str,
        payloads: &[serde_json::Value],
    ) -> Result<Vec<String>>;

    /// Total number of flush failures since startup.
    fn flush_failure_count(&self) -> u64;
}