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(),
};
loop {
print!("Loading config ... ");
match ctx.load().await {
Ok(_) => {
break;
}
Err(err) => {
println!("error loading config: {err}, retrying in {CONFIG_RETRY} secs");
sleep_s(CONFIG_RETRY).await;
}
}
}
ctx.load().await.unwrap();
ctx
}
@ -118,6 +109,7 @@ impl Context {
.get_matches()
}
#[allow(dead_code)]
pub async fn discovery(&self) -> Result<Discovery, ReqError> {
let resp: Result<Response, ReqError> = self
.client
@ -139,8 +131,17 @@ impl Context {
if cfg!(test) {
return Ok(());
}
self.discovery = self.discovery().await?;
self.cfg.load(self.to_owned()).await?;
loop {
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?;
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>) {
let now_cfg_reload = Local::now().trunc_subsecs(0);
if (now_cfg_reload - *last_cfg_reload) > Duration::seconds(5) {
// reload configuration from the server
let mut ctx = ctxclone.write().await;
match ctx.load().await {
Ok(_) => {
*last_cfg_reload = Local::now().trunc_subsecs(0);
}
Err(err) => {
println!("error loading config: {err}");
}
Err(_) => {}
}
};
}