Skip to main content

meathook/
sink.rs

1//! The [`Sink`] trait and window metadata passed alongside records.
2
3use std::error;
4use std::future::Future;
5
6use time::OffsetDateTime;
7
8#[cfg(feature = "huggingface")]
9pub mod huggingface;
10
11/// Metadata describing the time window a batch of records belongs to.
12#[derive(Debug, Clone, PartialEq)]
13pub struct WindowMeta {
14    /// Pipeline (collector) name; used for partitioning storage paths.
15    pub pipeline: String,
16    /// Start of the window the records were collected in.
17    pub start: OffsetDateTime,
18    /// End of the window (the time the batch was handed over).
19    pub end: OffsetDateTime,
20}
21
22/// A destination for records.
23///
24/// Sinks compose like tower layers: a buffering layer may hold records until
25/// its flush policy fires, a durable layer appends them to disk, and a
26/// terminal sink ships them to long-term storage. See
27/// [`SinkExt`](crate::SinkExt) for the combinators.
28pub trait Sink<R>: Send {
29    /// Concrete error type (a `thiserror` enum, not a boxed error).
30    type Error: error::Error + Send + Sync + 'static;
31
32    /// Hand records to this layer. A buffering layer may hold them; a
33    /// terminal sink ships them immediately.
34    fn ingest(
35        &mut self,
36        meta: &WindowMeta,
37        records: Vec<R>,
38    ) -> impl Future<Output = Result<(), Self::Error>> + Send;
39
40    /// Force-drain this layer and everything downstream (shutdown, final
41    /// flush, startup recovery).
42    fn flush(&mut self) -> impl Future<Output = Result<(), Self::Error>> + Send;
43}