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.reindex import ReindexProgress
|
||||||
from home.src.index.video import SponsorBlock, YoutubeVideo
|
from home.src.index.video import SponsorBlock, YoutubeVideo
|
||||||
from home.src.ta.config import AppConfig
|
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.task_manager import TaskCommand, TaskManager
|
||||||
from home.src.ta.urlparser import Parser
|
from home.src.ta.urlparser import Parser
|
||||||
from home.tasks import (
|
from home.tasks import (
|
||||||
BaseTask,
|
BaseTask,
|
||||||
check_reindex,
|
check_reindex,
|
||||||
download_pending,
|
|
||||||
extrac_dl,
|
extrac_dl,
|
||||||
subscribe_to,
|
subscribe_to,
|
||||||
)
|
)
|
||||||
|
@ -436,12 +435,7 @@ class DownloadApiView(ApiBaseView):
|
||||||
return Response({"message": message}, status=404)
|
return Response({"message": message}, status=404)
|
||||||
|
|
||||||
print(f"{video_id}: change status to {item_status}")
|
print(f"{video_id}: change status to {item_status}")
|
||||||
if item_status == "priority":
|
PendingInteract(video_id, item_status).update_status()
|
||||||
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)
|
|
||||||
|
|
||||||
return Response(request.data)
|
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.index.video_streams import DurationConverter
|
||||||
from home.src.ta.config import AppConfig
|
from home.src.ta.config import AppConfig
|
||||||
from home.src.ta.helper import is_shorts
|
from home.src.ta.helper import is_shorts
|
||||||
from home.src.ta.ta_redis import RedisQueue
|
|
||||||
|
|
||||||
|
|
||||||
class PendingIndex:
|
class PendingIndex:
|
||||||
|
@ -113,21 +112,15 @@ class PendingInteract:
|
||||||
_, _ = ElasticWrap(path).post(data=data)
|
_, _ = ElasticWrap(path).post(data=data)
|
||||||
|
|
||||||
def update_status(self):
|
def update_status(self):
|
||||||
"""update status field of pending item"""
|
"""update status of pending item"""
|
||||||
data = {"doc": {"status": self.status}}
|
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}"
|
path = f"ta_download/_update/{self.youtube_id}"
|
||||||
_, _ = ElasticWrap(path).post(data=data)
|
_, _ = 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):
|
def get_item(self):
|
||||||
"""return pending item dict"""
|
"""return pending item dict"""
|
||||||
path = f"ta_download/_doc/{self.youtube_id}"
|
path = f"ta_download/_doc/{self.youtube_id}"
|
||||||
|
|
Loading…
Reference in New Issue