From 30a2dc2e20b48b324a847cb11d14f6f7802da208 Mon Sep 17 00:00:00 2001 From: Leonarda Prusina Date: Thu, 30 Apr 2026 22:46:02 +0200 Subject: [PATCH] update to 1.2 with proper health failure handling --- app/main.py | 14 ++++++++++---- k8s/moj-servis/deployment.yaml | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/main.py b/app/main.py index aaee55d..b192387 100644 --- a/app/main.py +++ b/app/main.py @@ -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 diff --git a/k8s/moj-servis/deployment.yaml b/k8s/moj-servis/deployment.yaml index 0e65d85..61c9283 100644 --- a/k8s/moj-servis/deployment.yaml +++ b/k8s/moj-servis/deployment.yaml @@ -15,7 +15,7 @@ spec: spec: containers: - name: moj-servis - image: git.fpmoz.sum.ba/leonarda11/moj-servis:1.1 + image: git.fpmoz.sum.ba/leonarda11/moj-servis:1.2 ports: - containerPort: 8000