simplify config update notification (#683)

This commit is contained in:
bmc-msft
2021-03-18 20:26:30 -04:00
committed by GitHub
parent 6e60a8cf10
commit 6b9ee20364
2 changed files with 6 additions and 14 deletions

View File

@ -154,18 +154,14 @@ impl Config {
Ok(())
}
pub async fn update(&mut self) -> Result<bool> {
pub async fn update(&mut self) -> Result<()> {
if self.fetch().await? {
info!("config updated");
self.save().await?;
proxy::update(&self.data).await?;
self.notify().await?;
}
let notified = if proxy::update(&self.data).await? {
self.notify().await?;
true
} else {
false
};
Ok(notified)
Ok(())
}
}

View File

@ -72,9 +72,8 @@ async fn restart_systemd() -> Result<()> {
Ok(())
}
pub async fn update(data: &ConfigData) -> Result<bool> {
pub async fn update(data: &ConfigData) -> Result<()> {
let configs = build(data);
let mut changed = false;
let mut config_dir = tokio::fs::read_dir(SYSTEMD_CONFIG_DIR).await?;
while let Some(entry) = config_dir.next().await {
@ -107,7 +106,6 @@ pub async fn update(data: &ConfigData) -> Result<bool> {
tokio::fs::write(&path, configs[&file_name].clone()).await?;
start_service(&file_name).await?;
changed = true;
}
} else {
info!("stopping proxy {}", file_name);
@ -115,7 +113,6 @@ pub async fn update(data: &ConfigData) -> Result<bool> {
tokio::fs::remove_file(&path).await?;
stop_service(&file_name).await?;
restart_systemd().await?;
changed = true;
}
}
@ -125,9 +122,8 @@ pub async fn update(data: &ConfigData) -> Result<bool> {
info!("adding service {}", file_name);
tokio::fs::write(&path, content).await?;
start_service(&file_name).await?;
changed = true;
}
}
Ok(changed)
Ok(())
}