use std::num::NonZeroU32;
use std::time::Duration;
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(default, deny_unknown_fields))]
#[non_exhaustive]
pub struct InboxPurgeRequest {
#[cfg_attr(
feature = "serde",
serde(
rename = "completed_retention_ms",
with = "reliar_core::serde_millis::optional_millis"
)
)]
pub completed_retention: Option<Duration>,
#[cfg_attr(
feature = "serde",
serde(
rename = "incomplete_retention_ms",
with = "reliar_core::serde_millis::optional_millis"
)
)]
pub incomplete_retention: Option<Duration>,
#[cfg_attr(
feature = "serde",
serde(
rename = "dead_retention_ms",
with = "reliar_core::serde_millis::optional_millis"
)
)]
pub dead_retention: Option<Duration>,
pub batch_size: NonZeroU32,
}
const DEFAULT_PURGE_BATCH_SIZE: NonZeroU32 = NonZeroU32::new(1_000).unwrap();
impl Default for InboxPurgeRequest {
fn default() -> Self {
Self {
completed_retention: Some(Duration::from_secs(7 * 24 * 60 * 60)),
incomplete_retention: None,
dead_retention: None,
batch_size: DEFAULT_PURGE_BATCH_SIZE,
}
}
}
impl InboxPurgeRequest {
#[must_use]
pub const fn completed_retention(mut self, retention: Option<Duration>) -> Self {
self.completed_retention = retention;
self
}
#[must_use]
pub const fn incomplete_retention(mut self, retention: Option<Duration>) -> Self {
self.incomplete_retention = retention;
self
}
#[must_use]
pub const fn dead_retention(mut self, retention: Option<Duration>) -> Self {
self.dead_retention = retention;
self
}
#[must_use]
pub const fn batch_size(mut self, batch_size: NonZeroU32) -> Self {
self.batch_size = batch_size;
self
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[non_exhaustive]
pub struct InboxPurgeReport {
pub completed_deleted: u64,
pub incomplete_deleted: u64,
pub dead_deleted: u64,
}
impl InboxPurgeReport {
#[must_use]
pub const fn new(completed_deleted: u64, incomplete_deleted: u64, dead_deleted: u64) -> Self {
Self {
completed_deleted,
incomplete_deleted,
dead_deleted,
}
}
}