liminal/durability/
config.rs1use std::time::Duration;
2
3use super::DurabilityError;
4
5#[derive(Clone, Copy, Debug, PartialEq, Eq)]
7pub enum DurabilityMode {
8 Ephemeral,
10 Durable,
12 DurableDedup,
14 DurableConversation,
16}
17
18#[derive(Clone, Copy, Debug, PartialEq, Eq)]
20pub enum CheckpointPolicy {
21 PerMessage,
23 PerBatch(usize),
25 ExplicitFlush,
27}
28
29#[derive(Clone, Copy, Debug, PartialEq, Eq)]
31pub struct DurabilityConfig {
32 mode: DurabilityMode,
34 partition_count: usize,
36 dedup_ttl: Duration,
38 checkpoint_policy: CheckpointPolicy,
40}
41
42impl DurabilityConfig {
43 pub fn new(
51 mode: DurabilityMode,
52 partition_count: usize,
53 dedup_ttl: Duration,
54 checkpoint_policy: CheckpointPolicy,
55 ) -> Result<Self, DurabilityError> {
56 if partition_count == 0 {
57 return Err(DurabilityError::ConfigError(
58 "partition_count must be at least 1".to_owned(),
59 ));
60 }
61
62 if mode == DurabilityMode::DurableDedup && dedup_ttl == Duration::ZERO {
63 return Err(DurabilityError::ConfigError(
64 "dedup_ttl must be greater than zero for DurableDedup mode".to_owned(),
65 ));
66 }
67
68 if checkpoint_policy == CheckpointPolicy::PerBatch(0) {
69 return Err(DurabilityError::ConfigError(
70 "checkpoint batch size must be at least 1".to_owned(),
71 ));
72 }
73
74 Ok(Self {
75 mode,
76 partition_count,
77 dedup_ttl,
78 checkpoint_policy,
79 })
80 }
81
82 #[must_use]
84 pub const fn mode(&self) -> DurabilityMode {
85 self.mode
86 }
87
88 #[must_use]
90 pub const fn partition_count(&self) -> usize {
91 self.partition_count
92 }
93
94 #[must_use]
96 pub const fn dedup_ttl(&self) -> Duration {
97 self.dedup_ttl
98 }
99
100 #[must_use]
102 pub const fn checkpoint_policy(&self) -> CheckpointPolicy {
103 self.checkpoint_policy
104 }
105}