rdune71's picture
Add Redis health status to the health check endpoint
ff328ca
from fastapi import FastAPI
from api.status import router as status_router
from api.chat import router as chat_router
from core.memory import check_redis_health
import logging
import time
app = FastAPI()
logger = logging.getLogger(__name__)
# Mount routers
app.include_router(status_router, prefix="/api")
app.include_router(chat_router, prefix="/api")
@app.get("/")
async def root():
logger.info("API root endpoint accessed")
return {"message": "AI Life Coach API is running"}
@app.get("/health")
async def health_check():
"""Comprehensive health check endpoint"""
redis_healthy = check_redis_health()
health_status = {
"status": "healthy" if redis_healthy else "degraded",
"services": {
"redis": "healthy" if redis_healthy else "unhealthy"
},
"timestamp": time.time()
}
if redis_healthy:
logger.info("Health check passed")
else:
logger.warning("Health check degraded")
return health_status
# Add startup event for initialization logging
@app.on_event("startup")
async def startup_event():
logger.info("AI Life Coach API starting up...")
redis_healthy = check_redis_health()
logger.info("Redis health: %s", "healthy" if redis_healthy else "unhealthy")