yangdx
commited on
Commit
·
b6c0e2f
1
Parent(s):
4435ee9
feat(api): enhance document clearing error handling and status reporting
Browse files- Change pipeline busy status from "error" to "busy"
- Improve error handling documentation
lightrag/api/routers/document_routes.py
CHANGED
|
@@ -767,10 +767,16 @@ def create_document_routes(
|
|
| 767 |
|
| 768 |
Returns:
|
| 769 |
InsertResponse: A response object containing the status and message.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 770 |
|
| 771 |
Raises:
|
| 772 |
-
HTTPException:
|
| 773 |
-
|
| 774 |
"""
|
| 775 |
from lightrag.kg.shared_storage import get_namespace_data, get_pipeline_status_lock
|
| 776 |
|
|
@@ -782,7 +788,7 @@ def create_document_routes(
|
|
| 782 |
async with pipeline_status_lock:
|
| 783 |
if pipeline_status.get("busy", False):
|
| 784 |
return InsertResponse(
|
| 785 |
-
status="
|
| 786 |
message="Cannot clear documents while pipeline is busy"
|
| 787 |
)
|
| 788 |
# Set busy to true
|
|
@@ -843,6 +849,17 @@ def create_document_routes(
|
|
| 843 |
f"Successfully dropped all {storage_success_count} storage components"
|
| 844 |
)
|
| 845 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 846 |
# Log file deletion start
|
| 847 |
if "history_messages" in pipeline_status:
|
| 848 |
pipeline_status["history_messages"].append("Starting to delete files in input directory")
|
|
|
|
| 767 |
|
| 768 |
Returns:
|
| 769 |
InsertResponse: A response object containing the status and message.
|
| 770 |
+
- status="success": All documents and files were successfully cleared.
|
| 771 |
+
- status="partial_success": Document clear job exit with some errors.
|
| 772 |
+
- status="busy": Operation could not be completed because the pipeline is busy.
|
| 773 |
+
- status="fail": All storage drop operations failed, with message
|
| 774 |
+
- message: Detailed information about the operation results, including counts
|
| 775 |
+
of deleted files and any errors encountered.
|
| 776 |
|
| 777 |
Raises:
|
| 778 |
+
HTTPException: Raised when a serious error occurs during the clearing process,
|
| 779 |
+
with status code 500 and error details in the detail field.
|
| 780 |
"""
|
| 781 |
from lightrag.kg.shared_storage import get_namespace_data, get_pipeline_status_lock
|
| 782 |
|
|
|
|
| 788 |
async with pipeline_status_lock:
|
| 789 |
if pipeline_status.get("busy", False):
|
| 790 |
return InsertResponse(
|
| 791 |
+
status="busy",
|
| 792 |
message="Cannot clear documents while pipeline is busy"
|
| 793 |
)
|
| 794 |
# Set busy to true
|
|
|
|
| 849 |
f"Successfully dropped all {storage_success_count} storage components"
|
| 850 |
)
|
| 851 |
|
| 852 |
+
# If all storage operations failed, return error status and don't proceed with file deletion
|
| 853 |
+
if storage_success_count == 0 and storage_error_count > 0:
|
| 854 |
+
error_message = "All storage drop operations failed. Aborting document clearing process."
|
| 855 |
+
logger.error(error_message)
|
| 856 |
+
if "history_messages" in pipeline_status:
|
| 857 |
+
pipeline_status["history_messages"].append(error_message)
|
| 858 |
+
return InsertResponse(
|
| 859 |
+
status="fail",
|
| 860 |
+
message=error_message
|
| 861 |
+
)
|
| 862 |
+
|
| 863 |
# Log file deletion start
|
| 864 |
if "history_messages" in pipeline_status:
|
| 865 |
pipeline_status["history_messages"].append("Starting to delete files in input directory")
|