From 4d65927410fa8c2456b5daef7153f5a1c1366ece Mon Sep 17 00:00:00 2001 From: Bulat Kurbanov Date: Mon, 19 Sep 2022 19:34:29 +0300 Subject: [PATCH] Add update lock --- src/main.rs | 2 +- src/updater.rs | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 83b3a92..e8b47a8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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" diff --git a/src/updater.rs b/src/updater.rs index 3d99149..0ff582b 100644 --- a/src/updater.rs +++ b/src/updater.rs @@ -259,7 +259,16 @@ async fn send_webhooks() -> Result<(), Box> { Ok(()) } +lazy_static! { + pub static ref UPDATE_LOCK: tokio::sync::Mutex<()> = tokio::sync::Mutex::new(()); +} + pub async fn update() -> Result<(), Box> { + 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 {