use std::time::Duration;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum PersistOverflow {
#[default]
Drop,
Block,
}
#[derive(Debug, Clone)]
pub struct PersistConfig {
pub queue_max: usize,
pub batch_max: usize,
pub batch_wait: Duration,
pub batch_enabled: bool,
pub overflow: PersistOverflow,
}
impl Default for PersistConfig {
fn default() -> Self {
Self {
queue_max: 8192,
batch_max: 32,
batch_wait: Duration::from_millis(5),
batch_enabled: true,
overflow: PersistOverflow::Drop,
}
}
}
impl PersistConfig {
pub(crate) fn normalized(self) -> Self {
Self {
queue_max: self.queue_max.max(1),
batch_max: self.batch_max.max(1),
batch_wait: self.batch_wait,
batch_enabled: self.batch_enabled,
overflow: self.overflow,
}
}
}