Files
pi-pm3/app/backend/api/health.py
michael 4f35df1781 Initial commit - Phase 3/4
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-06 13:46:22 -08:00

50 lines
1.0 KiB
Python

"""Health check endpoints."""
from fastapi import APIRouter
from pydantic import BaseModel
import aiosqlite
router = APIRouter()
class HealthResponse(BaseModel):
status: str
version: str
@router.get("/health", response_model=HealthResponse)
async def health_check():
"""Health check endpoint."""
return HealthResponse(
status="healthy",
version="0.1.0"
)
@router.get("/ready")
async def readiness_check():
"""Readiness check endpoint.
Checks:
- Database connectivity
"""
from .. import config
checks = {"database": False}
reasons = []
# Check database connectivity
try:
async with aiosqlite.connect(config.DATABASE_PATH) as db:
await db.execute("SELECT 1")
checks["database"] = True
except Exception as e:
reasons.append(f"Database: {str(e)}")
all_ready = all(checks.values())
return {
"ready": all_ready,
"checks": checks,
"reasons": reasons if not all_ready else None
}