update to 1.2 with proper health failure handling

This commit is contained in:
2026-04-30 22:46:02 +02:00
parent c99dbffa5a
commit 30a2dc2e20
2 changed files with 11 additions and 5 deletions

View File

@@ -1,8 +1,9 @@
from fastapi import FastAPI
from fastapi.responses import JSONResponse
app = FastAPI()
_healthy = True # DODANO
_healthy = True
@app.get("/")
@@ -10,14 +11,19 @@ def root():
return {"message": "Pozdrav svijete"}
# 🔥 HEALTH CHECK (BITNO: HTTP STATUS se mijenja)
@app.get("/health")
def health():
if not _healthy: # DODANO
return {"status": "unhealthy"}
if not _healthy:
return JSONResponse(
status_code=500,
content={"status": "unhealthy"}
)
return {"status": "ok"}
@app.post("/break") # DODANO
# 🔥 BREAK ENDPOINT (simulira kvar)
@app.post("/break")
def break_health():
global _healthy
_healthy = False