feat: implement config reloading

This commit is contained in:
Vladimir Rubin 2025-04-27 00:15:02 +03:00
parent 69f7c8c05f
commit d4ea33ebad
Signed by: vavakado
GPG key ID: CAB744727F36B524

View file

@ -65,6 +65,22 @@ async fn socket_server(disabled: Arc<AtomicBool>, notify: Arc<Notify>) {
cur_gamma
);
}
"reload" => {
trace!("reload dispatched");
let config_handle = config_handle();
let mut config = config_handle.write().await;
match Config::load(get_config_path()) {
Ok(cfg) => {
debug!("Config file found, loading...");
*config = cfg;
notify.notify_one();
}
Err(err) => {
error!("Failed to load config: {err}");
warn!("Using default config.");
}
}
}
"status_notify" => {
trace!("status_notify dispatched");
let now = get_time();
@ -250,9 +266,9 @@ async fn config_guard() -> tokio::sync::RwLockReadGuard<'static, Config> {
CONFIG.get().expect("config not init").read().await
}
// fn config_handle() -> Arc<RwLock<Config>> {
// CONFIG.get().expect("config not init").clone()
// }
fn config_handle() -> Arc<RwLock<Config>> {
CONFIG.get().expect("config not init").clone()
}
// async fn get_config() -> Config {
// let lock = CONFIG.get().expect("config not initialized").read().await;