Add update lock

This commit is contained in:
2022-09-19 19:34:29 +03:00
parent 93268c7524
commit 4d65927410
2 changed files with 10 additions and 1 deletions

View File

@@ -27,7 +27,7 @@ async fn update(headers: HeaderMap) -> &'static str {
match updater::update().await {
Ok(_) => log::info!("Updated!"),
Err(err) => log::info!("Updater err: {:?}", err),
}
};
});
"Update started"

View File

@@ -259,7 +259,16 @@ async fn send_webhooks() -> Result<(), Box<reqwest::Error>> {
Ok(())
}
lazy_static! {
pub static ref UPDATE_LOCK: tokio::sync::Mutex<()> = tokio::sync::Mutex::new(());
}
pub async fn update() -> Result<(), Box<dyn std::error::Error>> {
let _lock = match UPDATE_LOCK.try_lock() {
Ok(v) => v,
Err(err) => return Err(Box::new(err)),
};
log::info!("Start update...");
let pool = match get_postgres_pool().await {