update to 1.2 with proper health failure handling
This commit is contained in:
14
app/main.py
14
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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user