Files
rustytorch/crates/production/rtx-config/src/watcher.rs
T
2026-03-04 00:08:42 +00:00

62 lines
1.5 KiB
Rust

//! File watching for hot reloading configuration.
use crate::{ConfigResult, RuntimeConfig};
use std::path::PathBuf;
use std::sync::Arc;
use tokio::sync::broadcast;
/// File watch events.
#[derive(Debug, Clone)]
pub enum WatchEvent {
Modified { path: PathBuf },
Deleted { path: PathBuf },
Error { error: String },
}
/// Watcher configuration.
#[derive(Debug, Clone)]
pub struct WatcherConfig {
pub poll_interval: std::time::Duration,
pub ignore_patterns: Vec<String>,
}
impl Default for WatcherConfig {
fn default() -> Self {
Self {
poll_interval: std::time::Duration::from_millis(500),
ignore_patterns: vec![
"*.tmp".to_string(),
"*.swp".to_string(),
".git/**".to_string(),
],
}
}
}
/// Configuration file watcher.
#[derive(Debug)]
pub struct ConfigWatcher {
_runtime_config: Arc<RuntimeConfig>,
event_sender: broadcast::Sender<WatchEvent>,
}
impl ConfigWatcher {
pub async fn new(runtime_config: Arc<RuntimeConfig>) -> ConfigResult<Self> {
let (event_sender, _) = broadcast::channel(1000);
Ok(Self {
_runtime_config: runtime_config,
event_sender,
})
}
pub async fn watch_file(&self, _path: &std::path::Path) -> ConfigResult<()> {
// Placeholder implementation
Ok(())
}
pub fn subscribe(&self) -> broadcast::Receiver<WatchEvent> {
self.event_sender.subscribe()
}
}