fixed status codefor health
This commit is contained in:
10
app/main.py
10
app/main.py
@@ -1,6 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import signal
|
from fastapi import FastAPI, Response, status
|
||||||
from fastapi import FastAPI
|
from fastapi.responses import JSONResponse
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
_healthy = True
|
_healthy = True
|
||||||
@@ -9,13 +9,15 @@ _healthy = True
|
|||||||
@app.get("/health")
|
@app.get("/health")
|
||||||
def health():
|
def health():
|
||||||
if not _healthy:
|
if not _healthy:
|
||||||
return {"status": "unhealthy"}, 503
|
return JSONResponse(
|
||||||
|
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
|
||||||
|
content={"status": "unhealthy"}
|
||||||
|
)
|
||||||
return {"status": "ok"}
|
return {"status": "ok"}
|
||||||
|
|
||||||
|
|
||||||
@app.post("/break")
|
@app.post("/break")
|
||||||
def break_health():
|
def break_health():
|
||||||
"""Simulira pad servisa za testiranje liveness probe-a"""
|
|
||||||
global _healthy
|
global _healthy
|
||||||
_healthy = False
|
_healthy = False
|
||||||
return {"message": "Servis je sada nezdrav — ocekuj restart"}
|
return {"message": "Servis je sada nezdrav — ocekuj restart"}
|
||||||
|
|||||||
Reference in New Issue
Block a user