28 lines
656 B
Python
28 lines
656 B
Python
import time
|
|
|
|
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.core.database import get_db
|
|
|
|
router = APIRouter()
|
|
|
|
@router.get("/health")
|
|
async def health_check(db: Session = Depends(get_db)):
|
|
"""
|
|
Health check endpoint that verifies the API is running
|
|
and can connect to the database.
|
|
"""
|
|
try:
|
|
# Check database connection by executing a simple query
|
|
db.execute("SELECT 1")
|
|
db_status = "healthy"
|
|
except Exception as e:
|
|
db_status = f"unhealthy: {str(e)}"
|
|
|
|
return {
|
|
"status": "online",
|
|
"timestamp": time.time(),
|
|
"database": db_status,
|
|
}
|