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 max_watch_dirs: usize,
8    pub hash_cache_capacity: usize,
9}
10
11impl Default for WatcherConfig {
12    fn default() -> Self {
13        Self {
14            enabled: true,
15            debounce: Duration::from_secs(3),
16            max_watch_dirs: 1024,
17            hash_cache_capacity: 4096,
18        }
19    }
20}
21
22impl WatcherConfig {
23    pub const DEFAULT_DEBOUNCE_MS: u64 = 3000;
24    pub const DEFAULT_MAX_WATCH_DIRS: usize = 1024;
25    pub const DEFAULT_HASH_CACHE_CAPACITY: usize = 4096;
26
27    pub fn from_environment(overrides: &crate::env::WatcherEnvOverrides) -> Self {
28        Self {
29            enabled: overrides.enabled.unwrap_or(true),
30            debounce: Duration::from_millis(
31                overrides.debounce_ms.unwrap_or(Self::DEFAULT_DEBOUNCE_MS),
32            ),
33            max_watch_dirs: overrides
34                .max_watch_dirs
35                .unwrap_or(Self::DEFAULT_MAX_WATCH_DIRS),
36            hash_cache_capacity: overrides
37                .hash_cache_capacity
38                .unwrap_or(Self::DEFAULT_HASH_CACHE_CAPACITY),
39        }
40    }
41}
42
43#[cfg(test)]
44#[path = "mod_tests.rs"]
45mod tests;