Skip to content

Commit ad03ede

Browse files
authored
fix(sdk): add cancel_all_task_of call in stop_parsing endpoint (infiniflow#11748)
## Problem The SDK API endpoint `DELETE /datasets/{dataset_id}/chunks` only updates database status but does not send cancellation signal via Redis, causing background parsing tasks to continue and eventually complete (status becomes DONE instead of CANCEL). ## Root Cause The SDK endpoint was missing the `cancel_all_task_of(id)` call that the web API ([api/apps/document_app.py](cci:7://file:///d:/workspace1/ragflow-admin/api/apps/document_app.py:0:0-0:0)) uses to properly stop background tasks. ## Solution Added `cancel_all_task_of(id)` call in the [stop_parsing](cci:1://file:///d:/workspace1/ragflow/api/apps/sdk/doc.py:785:0-855:23) function to send cancellation signal via Redis, consistent with the web API behavior. ## Related Issue Fixes infiniflow#11745 Co-authored-by: tedhappy <tedhappy@users.noreply.github.com>
1 parent 468e404 commit ad03ede

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

api/apps/sdk/doc.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from api.db.services.knowledgebase_service import KnowledgebaseService
3434
from api.db.services.llm_service import LLMBundle
3535
from api.db.services.tenant_llm_service import TenantLLMService
36-
from api.db.services.task_service import TaskService, queue_tasks
36+
from api.db.services.task_service import TaskService, queue_tasks, cancel_all_task_of
3737
from api.db.services.dialog_service import meta_filter, convert_conditions
3838
from api.utils.api_utils import check_duplicate_ids, construct_json_result, get_error_data_result, get_parser_config, get_result, server_error_response, token_required, \
3939
get_request_json
@@ -835,6 +835,8 @@ async def stop_parsing(tenant_id, dataset_id):
835835
return get_error_data_result(message=f"You don't own the document {id}.")
836836
if int(doc[0].progress) == 1 or doc[0].progress == 0:
837837
return get_error_data_result("Can't stop parsing document with progress at 0 or 1")
838+
# Send cancellation signal via Redis to stop background task
839+
cancel_all_task_of(id)
838840
info = {"run": "2", "progress": 0, "chunk_num": 0}
839841
DocumentService.update_by_id(id, info)
840842
settings.docStoreConn.delete({"doc_id": doc[0].id}, search.index_name(tenant_id), dataset_id)

0 commit comments

Comments
 (0)