Available on crate features
config-reload and config only.Expand description
Universal configuration reloader for DFE components.
ConfigReloader<T> provides three reload triggers, any combination of
which can be enabled simultaneously:
- SIGHUP (Unix only) – standard daemon reload signal
- Periodic timer – reload every N seconds
- File polling – detect config file changes via mtime comparison
The reloader calls a user-supplied reload_fn to load config and a
validate_fn to validate before applying. On success it updates the
SharedConfig<T> which notifies all subscribers.
§Usage
use std::path::PathBuf;
use std::time::Duration;
use hyperi_rustlib::config::reloader::{ConfigReloader, ReloaderConfig};
use hyperi_rustlib::config::shared::SharedConfig;
#[derive(Clone, Debug, Default)]
struct AppConfig {
pub workers: usize,
}
#[tokio::main]
async fn main() {
let config = AppConfig { workers: 4 };
let shared = SharedConfig::new(config);
let reloader_config = ReloaderConfig {
config_path: Some(PathBuf::from("config.yaml")),
poll_interval: Duration::from_secs(5),
periodic_interval: Duration::ZERO, // disabled
debounce: Duration::from_millis(500),
enable_sighup: true,
};
let reloader = ConfigReloader::new(
reloader_config,
shared.clone(),
|| {
// Your config loading logic here
Ok(AppConfig { workers: 8 })
},
|cfg| {
// Your validation logic here
if cfg.workers == 0 {
return Err("workers must be > 0".into());
}
Ok(())
},
);
let _handle = reloader.start();
// ... run your application ...
}Replaces the per-component reload implementations in dfe-loader
(ConfigWatcher, file polling), dfe-receiver (config_reload_task,
SIGHUP + periodic), and dfe-archiver: set the matching ReloaderConfig
fields and pass the component’s existing load/validate functions.
Structs§
- Config
Reloader - Reloader
Config - Configuration for the reloader.