add reindex task lock, implement add to running queue

This commit is contained in:
simon 2022-12-12 17:33:57 +07:00
parent c25af5cfaa
commit 3b3d151ec3
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
2 changed files with 17 additions and 3 deletions

View File

@ -77,6 +77,7 @@ class StartupCheck:
"downloading",
"dl_queue",
"dl_queue_id",
"reindex",
"rescan",
"run_backup",
]

View File

@ -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