From 343995fd8fcb8da23b6fa1b7f78433da18f08f81 Mon Sep 17 00:00:00 2001 From: Scott Date: Sat, 7 Oct 2023 10:40:34 +0800 Subject: [PATCH] (improve)add health check to python service (#167) --- assembly/bin/supersonic-daemon.sh | 21 ++++++++++++++++++- .../src/main/python/supersonic_llmparser.py | 4 ++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/assembly/bin/supersonic-daemon.sh b/assembly/bin/supersonic-daemon.sh index 62a9aa8b4..6e31c4c06 100755 --- a/assembly/bin/supersonic-daemon.sh +++ b/assembly/bin/supersonic-daemon.sh @@ -9,6 +9,8 @@ readonly CHAT_SERVICE="chat" readonly SEMANTIC_SERVICE="semantic" readonly LLMPARSER_SERVICE="llmparser" readonly STANDALONE_SERVICE="standalone" +readonly LLMPARSER_HOST="127.0.0.1" +readonly LLMPARSER_PORT="9092" sbinDir=$(cd "$(dirname "$0")"; pwd) baseDir=$(cd "$sbinDir/.." && pwd -P) @@ -88,7 +90,24 @@ function runPythonService { pythonRunDir=${runtimeDir}/supersonic-${model_name}/llmparser cd $pythonRunDir nohup ${python_path} supersonic_llmparser.py > $pythonRunDir/llmparser.log 2>&1 & - sleep 4 + # Add health check + for i in {1..10} + do + echo "Performing health check attempt $i..." + response=$(curl -s http://${LLMPARSER_HOST}:${LLMPARSER_PORT}/health | jq -r '.status') + if [ "$response" == "Healthy" ]; then + echo "Health check passed." + break + else + echo "Health check failed with status: $response" + if [ "$i" -eq 10 ]; then + echo "Health check failed after 10 attempts. Exiting." + exit 1 + fi + echo "Retrying after 5 seconds..." + sleep 5 + fi + done } function reloadExamples { diff --git a/chat/core/src/main/python/supersonic_llmparser.py b/chat/core/src/main/python/supersonic_llmparser.py index 66587e7ad..a1c7bc3c3 100644 --- a/chat/core/src/main/python/supersonic_llmparser.py +++ b/chat/core/src/main/python/supersonic_llmparser.py @@ -19,6 +19,10 @@ from services_router import (query2sql_service, preset_query_service, app = FastAPI() +@app.get("/health") +def read_health(): + return {"status": "Healthy"} + app.include_router(preset_query_service.router) app.include_router(solved_query_service.router) app.include_router(query2sql_service.router)