fixed status codefor health

This commit is contained in:
ITO Mac
2026-05-04 18:32:59 +02:00
parent 35467e0d7c
commit ad9ae1c2a6

View File

@@ -1,6 +1,6 @@
import os import os
import signal from fastapi import FastAPI, Response, status
from fastapi import FastAPI from fastapi.responses import JSONResponse
app = FastAPI() app = FastAPI()
_healthy = True _healthy = True
@@ -9,13 +9,15 @@ _healthy = True
@app.get("/health") @app.get("/health")
def health(): def health():
if not _healthy: if not _healthy:
return {"status": "unhealthy"}, 503 return JSONResponse(
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
content={"status": "unhealthy"}
)
return {"status": "ok"} return {"status": "ok"}
@app.post("/break") @app.post("/break")
def break_health(): def break_health():
"""Simulira pad servisa za testiranje liveness probe-a"""
global _healthy global _healthy
_healthy = False _healthy = False
return {"message": "Servis je sada nezdrav — ocekuj restart"} return {"message": "Servis je sada nezdrav — ocekuj restart"}