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

View File

@@ -15,7 +15,7 @@ spec:
spec: spec:
containers: containers:
- name: moj-servis - name: moj-servis
image: git.fpmoz.sum.ba/leonarda11/moj-servis:1.1 image: git.fpmoz.sum.ba/leonarda11/moj-servis:1.2
ports: ports:
- containerPort: 8000 - containerPort: 8000