Don't send health api request multiple time if fails

This commit is contained in:
lalitdeore12@gmail.com
2025-03-12 10:28:52 +05:30
parent d17713ce4e
commit aa49670dbb
+23 -34
View File
@@ -122,45 +122,34 @@ jobs:
exit 1 exit 1
fi fi
MAX_RETRIES=5 # Total attempts (1 initial + 4 retries) echo "Waiting 1 minute before sending the health API request..."
RETRY_INTERVAL=10 # Retry every 10 seconds after first failure sleep 60
echo "Waiting 1 minute before the first health check..." echo "Checking health API..."
sleep 60 # Initial wait before first attempt HEALTH_RESPONSE=$(curl -s 'http://localhost:3001/api/v1/health?force=true' \
-H "Authorization: Bearer $API_KEY")
for ((i=1; i<=$MAX_RETRIES; i++)); do echo "Health API Response: $HEALTH_RESPONSE"
echo "Attempt $i/$MAX_RETRIES: Checking health API..."
HEALTH_RESPONSE=$(curl -s 'http://localhost:3001/api/v1/health?force=true' \ WORKFLOWS_CREATE=$(echo "$HEALTH_RESPONSE" | jq -r '.workflows.create')
-H "Authorization: Bearer $API_KEY") WORKFLOWS_RUN=$(echo "$HEALTH_RESPONSE" | jq -r '.workflows.run')
WORKFLOWS_RUN_FINISHED=$(echo "$HEALTH_RESPONSE" | jq -r '.workflows.run_finished')
WORKFLOWS_RUN_STATUS=$(echo "$HEALTH_RESPONSE" | jq -r '.workflows.run_status')
WORKFLOWS_DELETE=$(echo "$HEALTH_RESPONSE" | jq -r '.workflows.delete')
echo "Health API Response: $HEALTH_RESPONSE" echo "WORKFLOWS_CREATE: $WORKFLOWS_CREATE"
echo "WORKFLOWS_RUN: $WORKFLOWS_RUN"
echo "WORKFLOWS_RUN_FINISHED: $WORKFLOWS_RUN_FINISHED"
echo "WORKFLOWS_RUN_STATUS: $WORKFLOWS_RUN_STATUS"
echo "WORKFLOWS_DELETE: $WORKFLOWS_DELETE"
WORKFLOWS_CREATE=$(echo "$HEALTH_RESPONSE" | jq -r '.workflows.create') if [ "$WORKFLOWS_CREATE" = "true" ] && [ "$WORKFLOWS_RUN" = "true" ] && [ "$WORKFLOWS_RUN_FINISHED" = "true" ] && [ "$WORKFLOWS_RUN_STATUS" = "FINISHED" ] && [ "$WORKFLOWS_DELETE" = "true" ]; then
WORKFLOWS_RUN=$(echo "$HEALTH_RESPONSE" | jq -r '.workflows.run') echo "Health endpoint check was successful."
WORKFLOWS_RUN_FINISHED=$(echo "$HEALTH_RESPONSE" | jq -r '.workflows.run_finished') exit 0
WORKFLOWS_RUN_STATUS=$(echo "$HEALTH_RESPONSE" | jq -r '.workflows.run_status') else
WORKFLOWS_DELETE=$(echo "$HEALTH_RESPONSE" | jq -r '.workflows.delete') echo "Health check failed."
exit 1
echo "WORKFLOWS_CREATE: $WORKFLOWS_CREATE" fi
echo "WORKFLOWS_RUN: $WORKFLOWS_RUN"
echo "WORKFLOWS_RUN_FINISHED: $WORKFLOWS_RUN_FINISHED"
echo "WORKFLOWS_RUN_STATUS: $WORKFLOWS_RUN_STATUS"
echo "WORKFLOWS_DELETE: $WORKFLOWS_DELETE"
if [ "$WORKFLOWS_CREATE" = "true" ] && [ "$WORKFLOWS_RUN" = "true" ] && [ "$WORKFLOWS_RUN_FINISHED" = "true" ] && [ "$WORKFLOWS_RUN_STATUS" = "FINISHED" ] && [ "$WORKFLOWS_DELETE" = "true" ]; then
echo "Health endpoint check was successful."
exit 0
fi
if [ "$i" -lt "$MAX_RETRIES" ]; then
echo "Health check failed. Retrying in $RETRY_INTERVAL seconds..."
sleep $RETRY_INTERVAL
fi
done
echo "Health check failed after $MAX_RETRIES attempts."
exit 1
notify: notify:
needs: build needs: build