yangdx
commited on
Commit
Β·
86f2cf7
1
Parent(s):
e14243c
Add concurrency check for auto scan task to prevent duplicate scans
Browse filesβ’ Add pipeline status check before scan
β’ Add storage lock protection
β’ Add latest_message to status tracking
β’ Add helpful log message at startup
lightrag/api/lightrag_server.py
CHANGED
@@ -145,10 +145,25 @@ def create_app(args):
|
|
145 |
|
146 |
# Auto scan documents if enabled
|
147 |
if args.auto_scan_at_startup:
|
148 |
-
#
|
149 |
-
|
150 |
-
|
151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
|
153 |
ASCIIColors.green("\nServer is ready to accept connections! π\n")
|
154 |
|
|
|
145 |
|
146 |
# Auto scan documents if enabled
|
147 |
if args.auto_scan_at_startup:
|
148 |
+
# Import necessary functions from shared_storage
|
149 |
+
from lightrag.kg.shared_storage import get_namespace_data, get_storage_lock
|
150 |
+
|
151 |
+
# Get pipeline status and lock
|
152 |
+
pipeline_status = get_namespace_data("pipeline_status")
|
153 |
+
storage_lock = get_storage_lock()
|
154 |
+
|
155 |
+
# Check if a task is already running (with lock protection)
|
156 |
+
should_start_task = False
|
157 |
+
with storage_lock:
|
158 |
+
if not pipeline_status.get("busy", False):
|
159 |
+
should_start_task = True
|
160 |
+
# Only start the task if no other task is running
|
161 |
+
if should_start_task:
|
162 |
+
# Create background task
|
163 |
+
task = asyncio.create_task(run_scanning_process(rag, doc_manager))
|
164 |
+
app.state.background_tasks.add(task)
|
165 |
+
task.add_done_callback(app.state.background_tasks.discard)
|
166 |
+
logger.info("Auto scan task started at startup.")
|
167 |
|
168 |
ASCIIColors.green("\nServer is ready to accept connections! π\n")
|
169 |
|
lightrag/kg/shared_storage.py
CHANGED
@@ -91,6 +91,7 @@ def initialize_share_data(workers: int = 1):
|
|
91 |
"batchs": 0, # Number of batches for processing documents
|
92 |
"cur_batch": 0, # Current processing batch
|
93 |
"request_pending": False, # Flag for pending request for processing
|
|
|
94 |
})
|
95 |
|
96 |
|
|
|
91 |
"batchs": 0, # Number of batches for processing documents
|
92 |
"cur_batch": 0, # Current processing batch
|
93 |
"request_pending": False, # Flag for pending request for processing
|
94 |
+
"latest_message": "" # Latest message from pipeline processing
|
95 |
})
|
96 |
|
97 |
|