feat: implement config reloading
This commit is contained in:
parent
69f7c8c05f
commit
d4ea33ebad
1 changed files with 19 additions and 3 deletions
22
src/main.rs
22
src/main.rs
|
@ -65,6 +65,22 @@ async fn socket_server(disabled: Arc<AtomicBool>, notify: Arc<Notify>) {
|
||||||
cur_gamma
|
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" => {
|
"status_notify" => {
|
||||||
trace!("status_notify dispatched");
|
trace!("status_notify dispatched");
|
||||||
let now = get_time();
|
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
|
CONFIG.get().expect("config not init").read().await
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn config_handle() -> Arc<RwLock<Config>> {
|
fn config_handle() -> Arc<RwLock<Config>> {
|
||||||
// CONFIG.get().expect("config not init").clone()
|
CONFIG.get().expect("config not init").clone()
|
||||||
// }
|
}
|
||||||
|
|
||||||
// async fn get_config() -> Config {
|
// async fn get_config() -> Config {
|
||||||
// let lock = CONFIG.get().expect("config not initialized").read().await;
|
// let lock = CONFIG.get().expect("config not initialized").read().await;
|
||||||
|
|
Loading…
Reference in a new issue