tubearchivist/tubearchivist/home/apps.py

64 lines
1.5 KiB
Python
Raw Normal View History

"""handle custom startup functions"""
import os
2021-09-05 17:10:14 +00:00
from django.apps import AppConfig
from home.src.config import AppConfig as ArchivistConfig
from home.src.helper import RedisArchivist
from home.src.index_management import index_check
2021-10-03 18:07:15 +00:00
def sync_redis_state():
"""make sure redis gets new config.json values"""
print("sync redis")
config_handler = ArchivistConfig()
config_handler.load_new_defaults()
def make_folders():
"""make needed cache folders here so docker doesn't mess it up"""
2021-11-10 10:55:34 +00:00
folders = [
"download",
"channels",
"videos",
"playlists",
"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"""
2021-12-02 12:11:45 +00:00
all_locks = [
"manual_import",
"downloading",
"dl_queue",
"dl_queue_id",
"rescan",
]
for lock in all_locks:
response = RedisArchivist().del_message(lock)
if response:
print("deleted leftover key from redis: " + lock)
2021-09-05 17:10:14 +00:00
class HomeConfig(AppConfig):
"""call startup funcs"""
2021-09-21 09:25:22 +00:00
default_auto_field = "django.db.models.BigAutoField"
name = "home"
def ready(self):
release_lock()
index_check()
2021-10-03 18:07:15 +00:00
sync_redis_state()
make_folders()