File size: 1,289 Bytes
4f94787
 
11ba014
b127732
0194326
ff328ca
4f94787
 
0194326
4f94787
ad2999f
4f94787
11ba014
4f94787
 
 
0194326
4f94787
b127732
 
 
0194326
b127732
0194326
 
ff328ca
0194326
 
 
ff328ca
b127732
0194326
ff328ca
0194326
 
 
 
 
 
 
 
 
 
ff328ca
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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")