2021-09-27 10:45:44 +00:00
|
|
|
"""handle custom startup functions"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
2021-09-05 17:10:14 +00:00
|
|
|
from django.apps import AppConfig
|
2021-09-27 10:45:44 +00:00
|
|
|
from home.src.config import AppConfig as ArchivistConfig
|
2021-09-28 03:33:00 +00:00
|
|
|
from home.src.helper import RedisArchivist
|
2021-09-27 10:45:44 +00:00
|
|
|
from home.src.index_management import index_check
|
|
|
|
|
|
|
|
|
|
|
|
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:
|
2021-09-28 03:33:00 +00:00
|
|
|
response = RedisArchivist().del_message(lock)
|
2021-09-27 10:45:44 +00:00
|
|
|
if response:
|
|
|
|
print("deleted leftover key from redis: " + lock)
|
2021-09-05 17:10:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class HomeConfig(AppConfig):
|
2021-09-27 10:45:44 +00:00
|
|
|
"""call startup funcs"""
|
|
|
|
|
2021-09-21 09:25:22 +00:00
|
|
|
default_auto_field = "django.db.models.BigAutoField"
|
|
|
|
name = "home"
|
2021-09-27 10:45:44 +00:00
|
|
|
|
|
|
|
def ready(self):
|
|
|
|
release_lock()
|
|
|
|
index_check()
|
|
|
|
make_folders()
|