refactor RedisQueue to take a queue_name arg

This commit is contained in:
simon 2022-12-10 14:51:17 +07:00
parent 37218fea1f
commit 49b120ed2b
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
5 changed files with 10 additions and 10 deletions

View File

@ -382,7 +382,7 @@ class DownloadApiView(ApiBaseView):
print(f"{video_id}: change status to {item_status}")
PendingInteract(video_id=video_id, status=item_status).update_status()
RedisQueue().clear_item(video_id)
RedisQueue(queue_name="dl_queue").clear_item(video_id)
return Response(request.data)

View File

@ -184,7 +184,7 @@ class VideoDownloader:
"""setup download queue in redis loop until no more items"""
self._setup_queue()
queue = RedisQueue()
queue = RedisQueue(queue_name="dl_queue")
limit_queue = self.config["downloads"]["limit_count"]
if limit_queue:
@ -275,7 +275,7 @@ class VideoDownloader:
RedisArchivist().set_message(self.MSG, mess_dict, expire=True)
return
RedisQueue().add_list(to_add)
RedisQueue(queue_name="dl_queue").add_list(to_add)
def _progress_hook(self, response):
"""process the progress_hooks from yt_dlp"""

View File

@ -123,7 +123,7 @@ class PostData:
print(f"{video_id}: ignore video from download queue")
PendingInteract(video_id=video_id, status="ignore").update_status()
# also clear from redis queue
RedisQueue().clear_item(video_id)
RedisQueue(queue_name="dl_queue").clear_item(video_id)
return {"success": True}
@staticmethod
@ -141,7 +141,7 @@ class PostData:
to_execute = self.exec_val
if to_execute == "stop":
print("stopping download queue")
RedisQueue().clear()
RedisQueue(queue_name="dl_queue").clear()
elif to_execute == "kill":
task_id = RedisArchivist().get_message("dl_queue_id")
if not isinstance(task_id, str):

View File

@ -102,11 +102,11 @@ class RedisArchivist(RedisBase):
class RedisQueue(RedisBase):
"""dynamically interact with the download queue in redis"""
"""dynamically interact with queues in redis"""
def __init__(self):
def __init__(self, queue_name):
super().__init__()
self.key = self.NAME_SPACE + "dl_queue"
self.key = f"{self.NAME_SPACE}{queue_name}"
def get_all(self):
"""return all elements in list"""

View File

@ -99,7 +99,7 @@ def download_pending():
@shared_task
def download_single(youtube_id):
"""start download single video now"""
queue = RedisQueue()
queue = RedisQueue(queue_name="dl_queue")
queue.add_priority(youtube_id)
print("Added to queue with priority: " + youtube_id)
# start queue if needed
@ -192,7 +192,7 @@ def kill_dl(task_id):
app.control.revoke(task_id, terminate=True)
_ = RedisArchivist().del_message("dl_queue_id")
RedisQueue().clear()
RedisQueue(queue_name="dl_queue").clear()
clear_dl_cache(CONFIG)