moove limit_count functionality into VideoDownload class to avoid having to reload the celery worker on config change

This commit is contained in:
simon 2021-09-09 12:28:25 +07:00
parent 97819318da
commit 641698c350
2 changed files with 6 additions and 7 deletions

View File

@ -375,6 +375,10 @@ class VideoDownloader:
def download_list(self):
""" download the list of youtube_ids """
limit_count = self.config['downloads']['limit_count']
if limit_count:
self.youtube_id_list = self.youtube_id_list[:limit_count]
for youtube_id in self.youtube_id_list:
try:
self.dl_single_vid(youtube_id)

View File

@ -17,7 +17,6 @@ from home.src.config import AppConfig
CONFIG = AppConfig().config
LIMIT_COUNT = CONFIG['downloads']['limit_count']
REDIS_HOST = CONFIG['application']['REDIS_HOST']
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'home.settings')
@ -41,12 +40,8 @@ def download_pending():
""" download latest pending videos """
pending_handler = PendingList()
pending_vids = pending_handler.get_all_pending()[0]
pending = [i['youtube_id'] for i in pending_vids]
pending.reverse()
if LIMIT_COUNT:
to_download = pending[:LIMIT_COUNT]
else:
to_download = pending
to_download = [i['youtube_id'] for i in pending_vids]
to_download.reverse()
if to_download:
download_handler = VideoDownloader(to_download)
download_handler.download_list()