mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-10 19:51:00 +00:00
(improve)add health check to python service (#167)
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user