refactor and run clear_dl_cache at startup

This commit is contained in:
simon 2022-11-25 18:49:36 +07:00
parent f619a5f72d
commit f6c702fba7
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
3 changed files with 14 additions and 6 deletions

View File

@ -8,6 +8,7 @@ from home.src.es.connect import ElasticWrap
from home.src.es.index_setup import index_check
from home.src.es.snapshot import ElasticSnapshot
from home.src.ta.config import AppConfig as ArchivistConfig
from home.src.ta.helper import clear_dl_cache
from home.src.ta.ta_redis import RedisArchivist
@ -27,6 +28,7 @@ class StartupCheck:
print("run startup checks")
self.es_version_check()
self.release_lock()
clear_dl_cache(self.config_handler.config)
index_check()
self.sync_redis_state()
self.set_redis_conf()

View File

@ -3,6 +3,7 @@ Loose collection of helper functions
- don't import AppConfig class here to avoid circular imports
"""
import os
import random
import re
import string
@ -117,6 +118,15 @@ def time_parser(timestamp):
return int(hours) * 60 * 60 + int(minutes) * 60 + float(seconds)
def clear_dl_cache(config):
"""clear leftover files from dl cache"""
print("clear download cache")
cache_dir = os.path.join(config["application"]["cache_dir"], "download")
for cached in os.listdir(cache_dir):
to_delete = os.path.join(cache_dir, cached)
os.remove(to_delete)
class UrlListParser:
"""take a multi line string and detect valid youtube ids"""

View File

@ -25,7 +25,7 @@ from home.src.index.filesystem import (
scan_filesystem,
)
from home.src.ta.config import AppConfig, ScheduleBuilder
from home.src.ta.helper import UrlListParser
from home.src.ta.helper import UrlListParser, clear_dl_cache
from home.src.ta.ta_redis import RedisArchivist, RedisQueue
CONFIG = AppConfig().config
@ -192,11 +192,7 @@ def kill_dl(task_id):
_ = RedisArchivist().del_message("dl_queue_id")
RedisQueue().clear()
# clear cache
cache_dir = os.path.join(CONFIG["application"]["cache_dir"], "download")
for cached in os.listdir(cache_dir):
to_delete = os.path.join(cache_dir, cached)
os.remove(to_delete)
clear_dl_cache(CONFIG)
# notify
mess_dict = {