From 3b3d151ec3dfa2ba738ab790525d1fadfad2066d Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 12 Dec 2022 17:33:57 +0700 Subject: [PATCH] add reindex task lock, implement add to running queue --- tubearchivist/home/apps.py | 1 + tubearchivist/home/tasks.py | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/tubearchivist/home/apps.py b/tubearchivist/home/apps.py index d52db7f..657c0e2 100644 --- a/tubearchivist/home/apps.py +++ b/tubearchivist/home/apps.py @@ -77,6 +77,7 @@ class StartupCheck: "downloading", "dl_queue", "dl_queue_id", + "reindex", "rescan", "run_backup", ] diff --git a/tubearchivist/home/tasks.py b/tubearchivist/home/tasks.py index 18ba2be..ee830e9 100644 --- a/tubearchivist/home/tasks.py +++ b/tubearchivist/home/tasks.py @@ -137,10 +137,23 @@ def check_reindex(data=False, extract_videos=False): """run the reindex main command""" if data: ReindexManual(extract_videos=extract_videos).extract_data(data) - else: - ReindexOutdated().add_outdated() - Reindex().reindex_all() + have_lock = False + reindex_lock = RedisArchivist().get_lock("reindex") + + try: + have_lock = reindex_lock.acquire(blocking=False) + if have_lock: + if not data: + ReindexOutdated().add_outdated() + + Reindex().reindex_all() + else: + print("Did not acquire reindex lock.") + + finally: + if have_lock: + reindex_lock.release() @shared_task