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