(improve)add health check to python service (#167)

This commit is contained in:
Scott
2023-10-07 10:40:34 +08:00
committed by GitHub
parent 71cb20eb4f
commit 343995fd8f
2 changed files with 24 additions and 1 deletions

View File

@@ -9,6 +9,8 @@ readonly CHAT_SERVICE="chat"
readonly SEMANTIC_SERVICE="semantic" readonly SEMANTIC_SERVICE="semantic"
readonly LLMPARSER_SERVICE="llmparser" readonly LLMPARSER_SERVICE="llmparser"
readonly STANDALONE_SERVICE="standalone" readonly STANDALONE_SERVICE="standalone"
readonly LLMPARSER_HOST="127.0.0.1"
readonly LLMPARSER_PORT="9092"
sbinDir=$(cd "$(dirname "$0")"; pwd) sbinDir=$(cd "$(dirname "$0")"; pwd)
baseDir=$(cd "$sbinDir/.." && pwd -P) baseDir=$(cd "$sbinDir/.." && pwd -P)
@@ -88,7 +90,24 @@ function runPythonService {
pythonRunDir=${runtimeDir}/supersonic-${model_name}/llmparser pythonRunDir=${runtimeDir}/supersonic-${model_name}/llmparser
cd $pythonRunDir cd $pythonRunDir
nohup ${python_path} supersonic_llmparser.py > $pythonRunDir/llmparser.log 2>&1 & 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 { function reloadExamples {

View File

@@ -19,6 +19,10 @@ from services_router import (query2sql_service, preset_query_service,
app = FastAPI() app = FastAPI()
@app.get("/health")
def read_health():
return {"status": "Healthy"}
app.include_router(preset_query_service.router) app.include_router(preset_query_service.router)
app.include_router(solved_query_service.router) app.include_router(solved_query_service.router)
app.include_router(query2sql_service.router) app.include_router(query2sql_service.router)