mirror of
https://github.com/tubearchivist/tubearchivist-frontend.git
synced 2024-11-04 19:30:13 +00:00
media files import with lock to force single run
This commit is contained in:
parent
297eb058cc
commit
7f6732422b
@ -100,6 +100,12 @@ def get_dl_message(cache_dir):
|
|||||||
return json_str
|
return json_str
|
||||||
|
|
||||||
|
|
||||||
|
def get_lock(lock_key):
|
||||||
|
""" handle lock for task management """
|
||||||
|
redis_lock = redis.Redis(host=REDIS_HOST).lock(lock_key)
|
||||||
|
return redis_lock
|
||||||
|
|
||||||
|
|
||||||
def monitor_cache_dir(cache_dir):
|
def monitor_cache_dir(cache_dir):
|
||||||
"""
|
"""
|
||||||
look at download cache dir directly as alterative progress info
|
look at download cache dir directly as alterative progress info
|
||||||
|
@ -15,6 +15,7 @@ from home.src.download import (
|
|||||||
)
|
)
|
||||||
from home.src.config import AppConfig
|
from home.src.config import AppConfig
|
||||||
from home.src.reindex import reindex_old_documents, ManualImport
|
from home.src.reindex import reindex_old_documents, ManualImport
|
||||||
|
from home.src.helper import get_lock
|
||||||
|
|
||||||
|
|
||||||
CONFIG = AppConfig().config
|
CONFIG = AppConfig().config
|
||||||
@ -75,7 +76,20 @@ def check_reindex():
|
|||||||
@shared_task
|
@shared_task
|
||||||
def run_manual_import():
|
def run_manual_import():
|
||||||
""" called from settings page, to go through import folder """
|
""" called from settings page, to go through import folder """
|
||||||
|
|
||||||
print('starting media file import')
|
print('starting media file import')
|
||||||
|
have_lock = False
|
||||||
|
my_lock = get_lock('manual_import')
|
||||||
|
|
||||||
|
try:
|
||||||
|
have_lock = my_lock.acquire(blocking=False)
|
||||||
|
if have_lock:
|
||||||
import_handler = ManualImport()
|
import_handler = ManualImport()
|
||||||
if import_handler.identified:
|
if import_handler.identified:
|
||||||
import_handler.process_import()
|
import_handler.process_import()
|
||||||
|
else:
|
||||||
|
print("Did not acquire lock form import.")
|
||||||
|
|
||||||
|
finally:
|
||||||
|
if have_lock:
|
||||||
|
my_lock.release()
|
||||||
|
Loading…
Reference in New Issue
Block a user