Skip to main content

azoth_core/config/
projector.rs

1use serde::{Deserialize, Serialize};
2
3/// Configuration for the projector
4#[derive(Debug, Clone, Serialize, Deserialize)]
5pub struct ProjectorConfig {
6    /// Maximum number of events per batch
7    /// Default: 1000
8    #[serde(default = "default_batch_events_max")]
9    pub batch_events_max: usize,
10
11    /// Maximum bytes per batch
12    /// Default: 4MB
13    #[serde(default = "default_batch_bytes_max")]
14    pub batch_bytes_max: usize,
15
16    /// Maximum apply latency in milliseconds
17    /// Projector tries to commit at least every N ms
18    /// Default: 100ms
19    #[serde(default = "default_max_apply_latency_ms")]
20    pub max_apply_latency_ms: u64,
21
22    /// Poll interval when caught up (milliseconds)
23    /// Default: 10ms
24    #[serde(default = "default_poll_interval_ms")]
25    pub poll_interval_ms: u64,
26
27    /// Maximum lag before throttling (number of events)
28    /// Default: 100000
29    #[serde(default = "default_max_lag_before_throttle")]
30    pub max_lag_before_throttle: u64,
31}
32
33fn default_batch_events_max() -> usize {
34    1000
35}
36
37fn default_batch_bytes_max() -> usize {
38    4 * 1024 * 1024 // 4MB
39}
40
41fn default_max_apply_latency_ms() -> u64 {
42    100
43}
44
45fn default_poll_interval_ms() -> u64 {
46    10
47}
48
49fn default_max_lag_before_throttle() -> u64 {
50    100_000
51}
52
53impl Default for ProjectorConfig {
54    fn default() -> Self {
55        Self {
56            batch_events_max: default_batch_events_max(),
57            batch_bytes_max: default_batch_bytes_max(),
58            max_apply_latency_ms: default_max_apply_latency_ms(),
59            poll_interval_ms: default_poll_interval_ms(),
60            max_lag_before_throttle: default_max_lag_before_throttle(),
61        }
62    }
63}
64
65impl ProjectorConfig {
66    pub fn new() -> Self {
67        Self::default()
68    }
69
70    pub fn with_batch_events_max(mut self, max: usize) -> Self {
71        self.batch_events_max = max;
72        self
73    }
74
75    pub fn with_batch_bytes_max(mut self, max: usize) -> Self {
76        self.batch_bytes_max = max;
77        self
78    }
79
80    pub fn with_max_apply_latency_ms(mut self, ms: u64) -> Self {
81        self.max_apply_latency_ms = ms;
82        self
83    }
84}