Add Redis health status to the health check endpoint
Browse files- api/main.py +6 -7
api/main.py
CHANGED
|
@@ -3,6 +3,7 @@ from api.status import router as status_router
|
|
| 3 |
from api.chat import router as chat_router
|
| 4 |
from core.memory import check_redis_health
|
| 5 |
import logging
|
|
|
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
logger = logging.getLogger(__name__)
|
|
@@ -21,18 +22,15 @@ async def health_check():
|
|
| 21 |
"""Comprehensive health check endpoint"""
|
| 22 |
redis_healthy = check_redis_health()
|
| 23 |
|
| 24 |
-
# Additional health checks could be added here
|
| 25 |
-
overall_healthy = redis_healthy
|
| 26 |
-
|
| 27 |
health_status = {
|
| 28 |
-
"status": "healthy" if
|
| 29 |
"services": {
|
| 30 |
"redis": "healthy" if redis_healthy else "unhealthy"
|
| 31 |
},
|
| 32 |
-
"timestamp":
|
| 33 |
}
|
| 34 |
|
| 35 |
-
if
|
| 36 |
logger.info("Health check passed")
|
| 37 |
else:
|
| 38 |
logger.warning("Health check degraded")
|
|
@@ -43,4 +41,5 @@ async def health_check():
|
|
| 43 |
@app.on_event("startup")
|
| 44 |
async def startup_event():
|
| 45 |
logger.info("AI Life Coach API starting up...")
|
| 46 |
-
|
|
|
|
|
|
| 3 |
from api.chat import router as chat_router
|
| 4 |
from core.memory import check_redis_health
|
| 5 |
import logging
|
| 6 |
+
import time
|
| 7 |
|
| 8 |
app = FastAPI()
|
| 9 |
logger = logging.getLogger(__name__)
|
|
|
|
| 22 |
"""Comprehensive health check endpoint"""
|
| 23 |
redis_healthy = check_redis_health()
|
| 24 |
|
|
|
|
|
|
|
|
|
|
| 25 |
health_status = {
|
| 26 |
+
"status": "healthy" if redis_healthy else "degraded",
|
| 27 |
"services": {
|
| 28 |
"redis": "healthy" if redis_healthy else "unhealthy"
|
| 29 |
},
|
| 30 |
+
"timestamp": time.time()
|
| 31 |
}
|
| 32 |
|
| 33 |
+
if redis_healthy:
|
| 34 |
logger.info("Health check passed")
|
| 35 |
else:
|
| 36 |
logger.warning("Health check degraded")
|
|
|
|
| 41 |
@app.on_event("startup")
|
| 42 |
async def startup_event():
|
| 43 |
logger.info("AI Life Coach API starting up...")
|
| 44 |
+
redis_healthy = check_redis_health()
|
| 45 |
+
logger.info("Redis health: %s", "healthy" if redis_healthy else "unhealthy")
|