@@ -77,8 +77,23 @@ def get_buffer(self, file):
7777 return self .buffer
7878
7979
80+ class BatchCancelInstanceSerializer (serializers .Serializer ):
81+ id_list = serializers .ListField (required = True , child = serializers .UUIDField (required = True ),
82+ error_messages = ErrMessage .char ("id列表" ))
83+ type = serializers .IntegerField (required = True , error_messages = ErrMessage .integer (
84+ "任务类型" ))
85+
86+ def is_valid (self , * , raise_exception = False ):
87+ super ().is_valid (raise_exception = True )
88+ _type = self .data .get ('type' )
89+ try :
90+ TaskType (_type )
91+ except Exception as e :
92+ raise AppApiException (500 , '任务类型不支持' )
93+
94+
8095class CancelInstanceSerializer (serializers .Serializer ):
81- type = serializers .IntegerField (required = True , error_messages = ErrMessage .boolean (
96+ type = serializers .IntegerField (required = True , error_messages = ErrMessage .integer (
8297 "任务类型" ))
8398
8499 def is_valid (self , * , raise_exception = False ):
@@ -1064,6 +1079,28 @@ def batch_delete(self, instance: Dict, with_valid=True):
10641079 delete_embedding_by_document_list (document_id_list )
10651080 return True
10661081
1082+ def batch_cancel (self , instance : Dict , with_valid = True ):
1083+ if with_valid :
1084+ self .is_valid (raise_exception = True )
1085+ BatchCancelInstanceSerializer (data = instance ).is_valid (raise_exception = True )
1086+ document_id_list = instance .get ("id_list" )
1087+ ListenerManagement .update_status (QuerySet (Paragraph ).annotate (
1088+ reversed_status = Reverse ('status' ),
1089+ task_type_status = Substr ('reversed_status' , TaskType (instance .get ('type' )).value ,
1090+ 1 ),
1091+ ).filter (task_type_status__in = [State .PENDING .value , State .STARTED .value ]).filter (
1092+ document_id__in = document_id_list ).values ('id' ),
1093+ TaskType (instance .get ('type' )),
1094+ State .REVOKE )
1095+ ListenerManagement .update_status (QuerySet (Document ).annotate (
1096+ reversed_status = Reverse ('status' ),
1097+ task_type_status = Substr ('reversed_status' , TaskType (instance .get ('type' )).value ,
1098+ 1 ),
1099+ ).filter (task_type_status__in = [State .PENDING .value , State .STARTED .value ]).filter (
1100+ id__in = document_id_list ).values ('id' ),
1101+ TaskType (instance .get ('type' )),
1102+ State .REVOKE )
1103+
10671104 def batch_edit_hit_handling (self , instance : Dict , with_valid = True ):
10681105 if with_valid :
10691106 BatchSerializer (data = instance ).is_valid (model = Document , raise_exception = True )
0 commit comments