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 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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user