Skip to main content

relay_knowledge/watcher/config/
mod.rs

1use std::time::Duration;
2
3#[derive(Debug, Clone, PartialEq, Eq)]
4pub struct WatcherConfig {
5    pub enabled: bool,
6    pub debounce: Duration,
7    pub commit_reconcile_interval: Duration,
8    pub max_watch_dirs: usize,
9    pub hash_cache_capacity: usize,
10}
11
12impl Default for WatcherConfig {
13    fn default() -> Self {
14        Self {
15            enabled: true,
16            debounce: Duration::from_secs(3),
17            commit_reconcile_interval: Duration::from_secs(5),
18            max_watch_dirs: 1024,
19            hash_cache_capacity: 4096,
20        }
21    }
22}
23
24impl WatcherConfig {
25    pub const DEFAULT_DEBOUNCE_MS: u64 = 3000;
26    pub const DEFAULT_COMMIT_RECONCILE_INTERVAL_MS: u64 = 5000;
27    pub const DEFAULT_MAX_WATCH_DIRS: usize = 1024;
28    pub const DEFAULT_HASH_CACHE_CAPACITY: usize = 4096;
29
30    pub fn from_environment(overrides: &crate::env::WatcherEnvOverrides) -> Self {
31        Self {
32            enabled: overrides.enabled.unwrap_or(true),
33            debounce: Duration::from_millis(
34                overrides.debounce_ms.unwrap_or(Self::DEFAULT_DEBOUNCE_MS),
35            ),
36            commit_reconcile_interval: Duration::from_millis(
37                overrides
38                    .commit_reconcile_interval_ms
39                    .unwrap_or(Self::DEFAULT_COMMIT_RECONCILE_INTERVAL_MS),
40            ),
41            max_watch_dirs: overrides
42                .max_watch_dirs
43                .unwrap_or(Self::DEFAULT_MAX_WATCH_DIRS),
44            hash_cache_capacity: overrides
45                .hash_cache_capacity
46                .unwrap_or(Self::DEFAULT_HASH_CACHE_CAPACITY),
47        }
48    }
49}
50
51#[cfg(test)]
52#[path = "mod_tests.rs"]
53mod tests;