updated config loading handling
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Paul 2023-04-17 22:31:10 +02:00
parent b1b5f4ef7d
commit 6a99d6b388
2 changed files with 16 additions and 18 deletions

View File

@ -81,18 +81,9 @@ impl Context {
hashwd: HashMap::new(), hashwd: HashMap::new(),
}; };
loop {
print!("Loading config ... "); print!("Loading config ... ");
match ctx.load().await { ctx.load().await.unwrap();
Ok(_) => {
break;
}
Err(err) => {
println!("error loading config: {err}, retrying in {CONFIG_RETRY} secs");
sleep_s(CONFIG_RETRY).await;
}
}
}
ctx ctx
} }
@ -118,6 +109,7 @@ impl Context {
.get_matches() .get_matches()
} }
#[allow(dead_code)]
pub async fn discovery(&self) -> Result<Discovery, ReqError> { pub async fn discovery(&self) -> Result<Discovery, ReqError> {
let resp: Result<Response, ReqError> = self let resp: Result<Response, ReqError> = self
.client .client
@ -139,8 +131,17 @@ impl Context {
if cfg!(test) { if cfg!(test) {
return Ok(()); return Ok(());
} }
self.discovery = self.discovery().await?; loop {
self.cfg.load(self.to_owned()).await?; match self.cfg.load(self.to_owned()).await {
Ok(()) => {
break;
}
Err(err) => {
println!("error loading config: {err}, retrying in {CONFIG_RETRY} secs");
sleep_s(CONFIG_RETRY).await;
}
};
}
self.create_sas().await?; self.create_sas().await?;
Ok(()) Ok(())
} }

View File

@ -126,15 +126,12 @@ pub async fn run() {
async fn handle_cfg_reload(ctxclone: Arc<RwLock<Context>>, last_cfg_reload: &mut DateTime<Local>) { async fn handle_cfg_reload(ctxclone: Arc<RwLock<Context>>, last_cfg_reload: &mut DateTime<Local>) {
let now_cfg_reload = Local::now().trunc_subsecs(0); let now_cfg_reload = Local::now().trunc_subsecs(0);
if (now_cfg_reload - *last_cfg_reload) > Duration::seconds(5) { if (now_cfg_reload - *last_cfg_reload) > Duration::seconds(5) {
// reload configuration from the server
let mut ctx = ctxclone.write().await; let mut ctx = ctxclone.write().await;
match ctx.load().await { match ctx.load().await {
Ok(_) => { Ok(_) => {
*last_cfg_reload = Local::now().trunc_subsecs(0); *last_cfg_reload = Local::now().trunc_subsecs(0);
} }
Err(err) => { Err(_) => {}
println!("error loading config: {err}");
}
} }
}; };
} }