consolidate update status priority
This commit is contained in:
parent
1b6b219e02
commit
89779ec13b
|
@ -12,13 +12,12 @@ from home.src.index.generic import Pagination
|
|||
from home.src.index.reindex import ReindexProgress
|
||||
from home.src.index.video import SponsorBlock, YoutubeVideo
|
||||
from home.src.ta.config import AppConfig
|
||||
from home.src.ta.ta_redis import RedisArchivist, RedisQueue
|
||||
from home.src.ta.ta_redis import RedisArchivist
|
||||
from home.src.ta.task_manager import TaskCommand, TaskManager
|
||||
from home.src.ta.urlparser import Parser
|
||||
from home.tasks import (
|
||||
BaseTask,
|
||||
check_reindex,
|
||||
download_pending,
|
||||
extrac_dl,
|
||||
subscribe_to,
|
||||
)
|
||||
|
@ -436,12 +435,7 @@ class DownloadApiView(ApiBaseView):
|
|||
return Response({"message": message}, status=404)
|
||||
|
||||
print(f"{video_id}: change status to {item_status}")
|
||||
if item_status == "priority":
|
||||
PendingInteract(youtube_id=video_id).prioritize()
|
||||
download_pending.delay(from_queue=False)
|
||||
else:
|
||||
PendingInteract(video_id, item_status).update_status()
|
||||
RedisQueue(queue_name="dl_queue").clear_item(video_id)
|
||||
PendingInteract(video_id, item_status).update_status()
|
||||
|
||||
return Response(request.data)
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@ from home.src.index.video_constants import VideoTypeEnum
|
|||
from home.src.index.video_streams import DurationConverter
|
||||
from home.src.ta.config import AppConfig
|
||||
from home.src.ta.helper import is_shorts
|
||||
from home.src.ta.ta_redis import RedisQueue
|
||||
|
||||
|
||||
class PendingIndex:
|
||||
|
@ -113,21 +112,15 @@ class PendingInteract:
|
|||
_, _ = ElasticWrap(path).post(data=data)
|
||||
|
||||
def update_status(self):
|
||||
"""update status field of pending item"""
|
||||
data = {"doc": {"status": self.status}}
|
||||
"""update status of pending item"""
|
||||
if self.status == "priority":
|
||||
data = {"doc": {"status": "pending", "auto_start": True}}
|
||||
else:
|
||||
data = {"doc": {"status": self.status}}
|
||||
|
||||
path = f"ta_download/_update/{self.youtube_id}"
|
||||
_, _ = ElasticWrap(path).post(data=data)
|
||||
|
||||
def prioritize(self):
|
||||
"""prioritize pending item in redis queue"""
|
||||
pending_video, _ = self.get_item()
|
||||
vid_type = pending_video.get("vid_type", VideoTypeEnum.VIDEOS.value)
|
||||
to_add = {
|
||||
"youtube_id": pending_video["youtube_id"],
|
||||
"vid_type": vid_type,
|
||||
}
|
||||
RedisQueue(queue_name="dl_queue").add_priority(to_add)
|
||||
|
||||
def get_item(self):
|
||||
"""return pending item dict"""
|
||||
path = f"ta_download/_doc/{self.youtube_id}"
|
||||
|
|
Loading…
Reference in New Issue