Expand description
File watcher for hot-reload of configuration files
This module provides the FileWatcher which monitors configuration directories
for file changes and automatically reloads configurations when files are modified.
§Hot-Reload Behavior
When a configuration file is modified:
- File change is detected (within 5 seconds)
- Configuration is re-parsed and validated
- If valid, configuration is updated in the registry
- If invalid, error is logged and previous configuration is retained
§Debouncing
Rapid file changes are debounced to avoid excessive reloads. The default
debounce delay is 500ms, which can be customized with FileWatcher::with_debounce.
§Usage
ⓘ
use ricecoder_storage::markdown_config::{ConfigurationLoader, ConfigRegistry, FileWatcher};
use std::sync::Arc;
use std::path::PathBuf;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let registry = Arc::new(ConfigRegistry::new());
let loader = Arc::new(ConfigurationLoader::new(registry.clone()));
let paths = vec![
PathBuf::from("~/.ricecoder/agents"),
PathBuf::from("projects/ricecoder/.agent"),
];
let mut watcher = FileWatcher::new(loader, paths);
// Start watching for changes
watcher.watch().await?;
Ok(())
}Structs§
- File
Watcher - File watcher for monitoring configuration file changes