From 04bd5413c991583c0c530834890e201cee8b0ba9 Mon Sep 17 00:00:00 2001 From: yangdx Date: Fri, 28 Feb 2025 12:21:50 +0800 Subject: [PATCH] Add API endpoint to retrieve document indexing pipeline status MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • GET /pipeline_status endpoint added • Returns current pipeline processing state --- lightrag/api/routers/document_routes.py | 29 +++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lightrag/api/routers/document_routes.py b/lightrag/api/routers/document_routes.py index 3bb36830..d2ff91f1 100644 --- a/lightrag/api/routers/document_routes.py +++ b/lightrag/api/routers/document_routes.py @@ -653,6 +653,35 @@ def create_document_routes( logging.error(traceback.format_exc()) raise HTTPException(status_code=500, detail=str(e)) + @router.get("/pipeline_status", dependencies=[Depends(optional_api_key)]) + async def get_pipeline_status(): + """ + Get the current status of the document indexing pipeline. + + This endpoint returns information about the current state of the document processing pipeline, + including whether it's busy, the current job name, when it started, how many documents + are being processed, how many batches there are, and which batch is currently being processed. + + Returns: + dict: A dictionary containing the pipeline status information + """ + try: + from lightrag.kg.shared_storage import get_namespace_data + pipeline_status = get_namespace_data("pipeline_status") + + # Convert to regular dict if it's a Manager.dict + status_dict = dict(pipeline_status) + + # Format the job_start time if it exists + if status_dict.get("job_start"): + status_dict["job_start"] = str(status_dict["job_start"]) + + return status_dict + except Exception as e: + logging.error(f"Error getting pipeline status: {str(e)}") + logging.error(traceback.format_exc()) + raise HTTPException(status_code=500, detail=str(e)) + @router.get("", dependencies=[Depends(optional_api_key)]) async def documents() -> DocsStatusesResponse: """