mirror of
https://git.vectorsigma.ru/public/tubearchivist.git
synced 2026-08-04 21:39:49 +00:00
add bulk status update in queue
This commit is contained in:
@@ -78,6 +78,22 @@ class AddToDownloadQuerySerializer(serializers.Serializer):
|
||||
autostart = serializers.BooleanField(required=False)
|
||||
|
||||
|
||||
class BulkUpdateDowloadQuerySerializer(serializers.Serializer):
|
||||
"""serialize bulk update query"""
|
||||
|
||||
filter = serializers.ChoiceField(choices=["pending", "ignore", "priority"])
|
||||
channel = serializers.CharField(required=False)
|
||||
vid_type = serializers.ChoiceField(
|
||||
choices=VideoTypeEnum.values_known(), required=False
|
||||
)
|
||||
|
||||
|
||||
class BulkUpdateDowloadDataSerializer(serializers.Serializer):
|
||||
"""serialize data"""
|
||||
|
||||
status = serializers.ChoiceField(choices=["pending", "ignore", "priority"])
|
||||
|
||||
|
||||
class DownloadQueueItemUpdateSerializer(serializers.Serializer):
|
||||
"""update single download queue item"""
|
||||
|
||||
|
||||
@@ -114,6 +114,30 @@ class PendingInteract:
|
||||
path = "ta_download/_delete_by_query?refresh=true"
|
||||
_, _ = ElasticWrap(path).post(data=data)
|
||||
|
||||
def update_bulk(
|
||||
self, channel_id: str | None, vid_type: str | None, new_status: str
|
||||
):
|
||||
"""update status in bulk"""
|
||||
must_list = [{"term": {"status": {"value": self.status}}}]
|
||||
if channel_id:
|
||||
must_list.append({"term": {"channel_id": {"value": channel_id}}})
|
||||
|
||||
if vid_type:
|
||||
must_list.append({"term": {"vid_type": {"value": vid_type}}})
|
||||
|
||||
data = {
|
||||
"query": {"bool": {"must": must_list}},
|
||||
"script": {
|
||||
"source": f"ctx._source.status = '{new_status}'",
|
||||
"lang": "painless",
|
||||
},
|
||||
}
|
||||
print(data)
|
||||
path = "ta_download/_update_by_query?refresh=true"
|
||||
response, status_code = ElasticWrap(path).post(data)
|
||||
print(status_code)
|
||||
print(response)
|
||||
|
||||
def update_status(self):
|
||||
"""update status of pending item"""
|
||||
if self.status == "priority":
|
||||
|
||||
@@ -8,6 +8,8 @@ from common.views_base import AdminOnly, ApiBaseView
|
||||
from download.serializers import (
|
||||
AddToDownloadListSerializer,
|
||||
AddToDownloadQuerySerializer,
|
||||
BulkUpdateDowloadDataSerializer,
|
||||
BulkUpdateDowloadQuerySerializer,
|
||||
DownloadAggsSerializer,
|
||||
DownloadItemSerializer,
|
||||
DownloadListQuerySerializer,
|
||||
@@ -120,6 +122,38 @@ class DownloadApiListView(ApiBaseView):
|
||||
|
||||
return Response(response_serializer.data)
|
||||
|
||||
@staticmethod
|
||||
@extend_schema(
|
||||
request=BulkUpdateDowloadDataSerializer(),
|
||||
parameters=[BulkUpdateDowloadQuerySerializer()],
|
||||
responses={204: OpenApiResponse(description="Status updated")},
|
||||
)
|
||||
def patch(request):
|
||||
"""bulk update status"""
|
||||
data_serializer = BulkUpdateDowloadDataSerializer(data=request.data)
|
||||
data_serializer.is_valid(raise_exception=True)
|
||||
validated_data = data_serializer.validated_data
|
||||
|
||||
new_status = validated_data["status"]
|
||||
|
||||
query_serializer = BulkUpdateDowloadQuerySerializer(
|
||||
data=request.query_params
|
||||
)
|
||||
query_serializer.is_valid(raise_exception=True)
|
||||
validated_query = query_serializer.validated_data
|
||||
status_filter = validated_query.get("filter")
|
||||
channel = validated_query.get("channel")
|
||||
vid_type = validated_query.get("vid_type")
|
||||
|
||||
PendingInteract(status=status_filter).update_bulk(
|
||||
channel_id=channel, vid_type=vid_type, new_status=new_status
|
||||
)
|
||||
|
||||
if new_status == "priority":
|
||||
download_pending.delay(auto_only=True)
|
||||
|
||||
return Response(status=204)
|
||||
|
||||
@extend_schema(
|
||||
parameters=[DownloadListQueueDeleteQuerySerializer()],
|
||||
responses={
|
||||
|
||||
Reference in New Issue
Block a user