mirror of
https://github.com/tubearchivist/tubearchivist-frontend.git
synced 2024-11-22 20:00:15 +00:00
moove startup functions to ready() method to avoid double execs
This commit is contained in:
parent
3d79f08311
commit
a242f744d5
@ -1,51 +1,5 @@
|
|||||||
""" handle startup """
|
""" handle celery startup """
|
||||||
|
|
||||||
import os
|
|
||||||
|
|
||||||
from home.src.config import AppConfig
|
|
||||||
from home.src.helper import del_message, set_message
|
|
||||||
from home.src.index_management import index_check
|
|
||||||
|
|
||||||
from .tasks import app as celery_app
|
from .tasks import app as celery_app
|
||||||
|
|
||||||
|
|
||||||
def sync_redis_state():
|
|
||||||
"""make sure redis gets the config.json values"""
|
|
||||||
print("sync redis")
|
|
||||||
config_handler = AppConfig()
|
|
||||||
config_handler.load_new_defaults()
|
|
||||||
config = config_handler.config
|
|
||||||
sort_order = config["archive"]["sort"]
|
|
||||||
set_message("sort_order", sort_order, expire=False)
|
|
||||||
hide_watched = bool(int(config["archive"]["hide_watched"]))
|
|
||||||
set_message("hide_watched", hide_watched, expire=False)
|
|
||||||
show_subed_only = bool(int(config["archive"]["show_subed_only"]))
|
|
||||||
set_message("show_subed_only", show_subed_only, expire=False)
|
|
||||||
|
|
||||||
|
|
||||||
def make_folders():
|
|
||||||
"""make needed cache folders here so docker doesn't mess it up"""
|
|
||||||
folders = ["download", "channels", "videos", "import", "backup"]
|
|
||||||
config = AppConfig().config
|
|
||||||
cache_dir = config["application"]["cache_dir"]
|
|
||||||
for folder in folders:
|
|
||||||
folder_path = os.path.join(cache_dir, folder)
|
|
||||||
try:
|
|
||||||
os.makedirs(folder_path)
|
|
||||||
except FileExistsError:
|
|
||||||
continue
|
|
||||||
|
|
||||||
|
|
||||||
def release_lock():
|
|
||||||
"""make sure there are no leftover locks set in redis on container start"""
|
|
||||||
all_locks = ["manual_import", "downloading"]
|
|
||||||
for lock in all_locks:
|
|
||||||
print("release leftover lock: " + lock)
|
|
||||||
del_message(lock)
|
|
||||||
|
|
||||||
|
|
||||||
__all__ = ("celery_app",)
|
__all__ = ("celery_app",)
|
||||||
make_folders()
|
|
||||||
sync_redis_state()
|
|
||||||
index_check()
|
|
||||||
release_lock()
|
|
||||||
|
@ -1,6 +1,57 @@
|
|||||||
|
"""handle custom startup functions"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
|
from home.src.config import AppConfig as ArchivistConfig
|
||||||
|
from home.src.helper import del_message, set_message
|
||||||
|
from home.src.index_management import index_check
|
||||||
|
|
||||||
|
|
||||||
|
def sync_redis_state():
|
||||||
|
"""make sure redis gets the config.json values"""
|
||||||
|
print("sync redis")
|
||||||
|
config_handler = ArchivistConfig()
|
||||||
|
config_handler.load_new_defaults()
|
||||||
|
config = config_handler.config
|
||||||
|
sort_order = config["archive"]["sort"]
|
||||||
|
set_message("sort_order", sort_order, expire=False)
|
||||||
|
hide_watched = bool(int(config["archive"]["hide_watched"]))
|
||||||
|
set_message("hide_watched", hide_watched, expire=False)
|
||||||
|
show_subed_only = bool(int(config["archive"]["show_subed_only"]))
|
||||||
|
set_message("show_subed_only", show_subed_only, expire=False)
|
||||||
|
|
||||||
|
|
||||||
|
def make_folders():
|
||||||
|
"""make needed cache folders here so docker doesn't mess it up"""
|
||||||
|
folders = ["download", "channels", "videos", "import", "backup"]
|
||||||
|
config = ArchivistConfig().config
|
||||||
|
cache_dir = config["application"]["cache_dir"]
|
||||||
|
for folder in folders:
|
||||||
|
folder_path = os.path.join(cache_dir, folder)
|
||||||
|
try:
|
||||||
|
os.makedirs(folder_path)
|
||||||
|
except FileExistsError:
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
|
def release_lock():
|
||||||
|
"""make sure there are no leftover locks set in redis on container start"""
|
||||||
|
all_locks = ["manual_import", "downloading", "dl_queue", "dl_queue_id"]
|
||||||
|
for lock in all_locks:
|
||||||
|
response = del_message(lock)
|
||||||
|
if response:
|
||||||
|
print("deleted leftover key from redis: " + lock)
|
||||||
|
|
||||||
|
|
||||||
class HomeConfig(AppConfig):
|
class HomeConfig(AppConfig):
|
||||||
|
"""call startup funcs"""
|
||||||
|
|
||||||
default_auto_field = "django.db.models.BigAutoField"
|
default_auto_field = "django.db.models.BigAutoField"
|
||||||
name = "home"
|
name = "home"
|
||||||
|
|
||||||
|
def ready(self):
|
||||||
|
release_lock()
|
||||||
|
index_check()
|
||||||
|
sync_redis_state()
|
||||||
|
make_folders()
|
||||||
|
Loading…
Reference in New Issue
Block a user