linkrs_sync/batch/
config.rs1use std::time::Duration;
2
3use linkrs_config::SyncFailurePolicy;
4
5#[derive(Debug, Clone)]
7pub struct BatchConfig {
8 pub batch_size: usize,
10 pub flush_interval: Duration,
12 pub max_buffer_size: usize,
14 pub enable_persistence: bool,
16 pub persistence_path: Option<std::path::PathBuf>,
18 pub failure_policy: SyncFailurePolicy,
20}
21
22impl Default for BatchConfig {
23 fn default() -> Self {
24 Self {
25 batch_size: 100,
26 flush_interval: Duration::from_secs(1),
27 max_buffer_size: 10000,
28 enable_persistence: false,
29 persistence_path: None,
30 failure_policy: SyncFailurePolicy::FailOpen,
31 }
32 }
33}
34
35impl BatchConfig {
36 pub fn new() -> Self {
37 Self::default()
38 }
39
40 pub fn with_batch_size(mut self, size: usize) -> Self {
41 self.batch_size = size;
42 self
43 }
44
45 pub fn with_flush_interval(mut self, interval: Duration) -> Self {
46 self.flush_interval = interval;
47 self
48 }
49
50 pub fn with_max_buffer_size(mut self, size: usize) -> Self {
51 self.max_buffer_size = size;
52 self
53 }
54
55 pub fn with_persistence(mut self, path: Option<std::path::PathBuf>) -> Self {
56 self.enable_persistence = path.is_some();
57 self.persistence_path = path;
58 self
59 }
60
61 pub fn with_failure_policy(mut self, policy: SyncFailurePolicy) -> Self {
62 self.failure_policy = policy;
63 self
64 }
65}
66
67impl From<crate::SyncConfig> for BatchConfig {
68 fn from(old: crate::SyncConfig) -> Self {
69 Self {
70 batch_size: old.batch_size,
71 flush_interval: Duration::from_millis(old.commit_interval_ms),
72 max_buffer_size: old.queue_size,
73 enable_persistence: false,
74 persistence_path: None,
75 failure_policy: old.failure_policy,
76 }
77 }
78}