refactor(search.py): moved initialization logic in search-txtai instance
All checks were successful
Deploy on push / deploy (push) Successful in 55s
All checks were successful
Deploy on push / deploy (push) Successful in 55s
This commit is contained in:
parent
316375bf18
commit
60a13a9097
|
@ -231,17 +231,10 @@ class SearchService:
|
|||
elif response.status_code == 500:
|
||||
db_error_count += 1
|
||||
|
||||
# If we've seen multiple 500s, check for DB corruption
|
||||
# If we've seen multiple 500s, log a critical error
|
||||
if db_error_count >= 3:
|
||||
logger.warning("Multiple server errors detected, attempting to reset search service")
|
||||
reset_result = await self.reset_search_service()
|
||||
if reset_result["status"] == "reset":
|
||||
logger.info("Search service has been reset, restarting batch processing")
|
||||
# Wait a moment for the service to stabilize
|
||||
await asyncio.sleep(2)
|
||||
# Only retry current batch
|
||||
retry_count = 0
|
||||
continue
|
||||
logger.critical(f"Multiple server errors detected (500). The search service may need manual intervention. Stopping batch {batch_id} processing.")
|
||||
break
|
||||
|
||||
# Try again with exponential backoff
|
||||
if retry_count < max_retries - 1:
|
||||
|
@ -276,13 +269,8 @@ class SearchService:
|
|||
if "duplicate key" in error_str or "unique constraint" in error_str or "nonetype" in error_str:
|
||||
db_error_count += 1
|
||||
if db_error_count >= 2:
|
||||
logger.warning(f"Database corruption detected: {error_str}")
|
||||
reset_result = await self.reset_search_service()
|
||||
if reset_result["status"] == "reset":
|
||||
logger.info("Search service has been reset, restarting batch processing")
|
||||
await asyncio.sleep(2)
|
||||
retry_count = 0
|
||||
continue
|
||||
logger.critical(f"Potential database corruption detected: {error_str}. The search service may need manual intervention. Stopping batch {batch_id} processing.")
|
||||
break
|
||||
|
||||
if retry_count < max_retries - 1:
|
||||
retry_count += 1
|
||||
|
@ -349,23 +337,6 @@ class SearchService:
|
|||
|
||||
return truncated_detail
|
||||
|
||||
async def reset_search_service(self):
|
||||
"""Reset the search service to recover from database corruption"""
|
||||
if not self.available:
|
||||
logger.warning("Search not available, cannot reset")
|
||||
return {"status": "disabled"}
|
||||
|
||||
try:
|
||||
logger.warning("Resetting search service due to database corruption")
|
||||
response = await self.client.post("/initialize")
|
||||
response.raise_for_status()
|
||||
result = response.json()
|
||||
logger.info(f"Search service reset: {result}")
|
||||
return {"status": "reset", "message": "Search index has been reset"}
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to reset search service: {e}")
|
||||
return {"status": "error", "message": str(e)}
|
||||
|
||||
async def search(self, text, limit, offset):
|
||||
"""Search documents"""
|
||||
if not self.available:
|
||||
|
|
Loading…
Reference in New Issue
Block a user