Fix (api): fix the document parsing status check logic (#12504)

### What problem does this PR solve?
When the original code terminates the parsing task halfway, the progress
may not be 0 or 1, which will result in the inability to call the
interface to parse again

-Change the document parsing progress check to task status check, and
use TaskStatus.RUNNING.value to judge
-Update the condition judgment for stopping parsing documents, and check
whether the task is running instead


### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
天海蒼灆
2026-02-28 14:38:55 +08:00
committed by GitHub
parent 32ec950ca8
commit 983150b936
3 changed files with 4 additions and 4 deletions

View File

@ -866,7 +866,7 @@ async def parse(tenant_id, dataset_id):
continue
if not doc:
return get_error_data_result(message=f"You don't own the document {id}.")
if 0.0 < doc[0].progress < 1.0:
if doc[0].run == TaskStatus.RUNNING.value:
return get_error_data_result("Can't parse document that is currently being processed")
info = {"run": "1", "progress": 0, "progress_msg": "", "chunk_num": 0, "token_num": 0}
DocumentService.update_by_id(id, info)
@ -946,8 +946,8 @@ async def stop_parsing(tenant_id, dataset_id):
doc = DocumentService.query(id=id, kb_id=dataset_id)
if not doc:
return get_error_data_result(message=f"You don't own the document {id}.")
if int(doc[0].progress) == 1 or doc[0].progress == 0:
return get_error_data_result("Can't stop parsing document with progress at 0 or 1")
if doc[0].run != TaskStatus.RUNNING.value :
return get_error_data_result("Can't stop parsing document that has not started or already completed")
# Send cancellation signal via Redis to stop background task
cancel_all_task_of(id)
info = {"run": "2", "progress": 0, "chunk_num": 0}