From 1b8181e34fbbc6a6dfb89afa704e1e1d8fe7ff68 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sun, 28 Jan 2024 20:25:43 +0100 Subject: show current import avaiil --- import/src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'import/src') diff --git a/import/src/lib.rs b/import/src/lib.rs index 97b9950..9618d96 100644 --- a/import/src/lib.rs +++ b/import/src/lib.rs @@ -39,9 +39,10 @@ use std::{ ops::Deref, path::{Path, PathBuf}, sync::{Arc, LazyLock}, + time::Duration, }; use tmdb::{parse_release_date, Tmdb}; -use tokio::{io::AsyncWriteExt, sync::Semaphore, task::spawn_blocking}; +use tokio::{io::AsyncWriteExt, sync::Semaphore, task::spawn_blocking, time::sleep}; use trakt::Trakt; static IMPORT_SEM: LazyLock = LazyLock::new(|| Semaphore::new(1)); @@ -51,9 +52,14 @@ struct Apis { tmdb: Option, } +pub fn is_importing() -> bool { + IMPORT_SEM.available_permits() <= 0 +} + pub async fn import(db: &DataAcid, fed: &Federation) -> anyhow::Result<()> { let permit = IMPORT_SEM.try_acquire()?; + sleep(Duration::from_secs(5)).await; { let txn = db.inner.begin_write()?; let mut table = txn.open_table(T_NODE_IMPORT)?; -- cgit v1.2.3-70-g09d2