relay_server/services/buffer/envelope_stack/
mod.rs

1use std::future::Future;
2
3use chrono::{DateTime, Utc};
4
5use crate::envelope::Envelope;
6
7pub mod caching;
8pub mod memory;
9pub mod sqlite;
10
11/// A stack-like data structure that holds [`Envelope`]s.
12pub trait EnvelopeStack: Send + std::fmt::Debug {
13    /// The error type that is returned when an error is encountered during reading or writing the
14    /// [`EnvelopeStack`].
15    type Error: std::fmt::Debug + std::error::Error;
16
17    /// Pushes an [`Envelope`] on top of the stack.
18    fn push(&mut self, envelope: Box<Envelope>) -> impl Future<Output = Result<(), Self::Error>>;
19
20    /// Peeks the [`Envelope`] on top of the stack.
21    fn peek(&mut self) -> impl Future<Output = Result<Option<DateTime<Utc>>, Self::Error>>;
22
23    /// Pops the [`Envelope`] on top of the stack.
24    fn pop(&mut self) -> impl Future<Output = Result<Option<Box<Envelope>>, Self::Error>>;
25
26    /// Persists all envelopes in the [`EnvelopeStack`]s to external storage, if possible,
27    /// and consumes the stack provider.
28    fn flush(self) -> impl Future<Output = ()>;
29}