Start integrating the onboarding flow with backend 14

This commit is contained in:
Urtzi Alfaro
2025-09-07 22:54:14 +02:00
parent 05898d504d
commit 0060b9cccb
13 changed files with 668 additions and 487 deletions

View File

@@ -12,10 +12,9 @@ import structlog
# Import core modules
from app.core.config import settings
from app.core.database import init_db, close_db
from app.core.database import init_db, close_db, health_check as db_health_check
from app.api import ingredients, stock, classification
from app.services.inventory_alert_service import InventoryAlertService
from shared.monitoring.health import router as health_router
from shared.monitoring.metrics import setup_metrics_early
# Auth decorators are used in endpoints, no global setup needed
@@ -127,7 +126,6 @@ async def general_exception_handler(request: Request, exc: Exception):
# Include routers
app.include_router(health_router, prefix="/health", tags=["health"])
app.include_router(ingredients.router, prefix=settings.API_V1_STR)
app.include_router(stock.router, prefix=settings.API_V1_STR)
app.include_router(classification.router, prefix=settings.API_V1_STR)
@@ -154,6 +152,49 @@ async def root():
}
@app.get("/health")
async def health_check():
"""Comprehensive health check endpoint"""
try:
# Check database health
db_health = await db_health_check()
# Check alert service health
alert_health = {"status": "not_initialized"}
if hasattr(app.state, 'alert_service') and app.state.alert_service:
try:
alert_health = await app.state.alert_service.health_check()
except Exception as e:
alert_health = {"status": "unhealthy", "error": str(e)}
# Determine overall health
overall_healthy = (
db_health and
alert_health.get("status") in ["healthy", "not_initialized"]
)
return {
"status": "healthy" if overall_healthy else "unhealthy",
"service": settings.SERVICE_NAME,
"version": settings.VERSION,
"database": "connected" if db_health else "disconnected",
"alert_service": alert_health,
"timestamp": structlog.get_logger().info("Health check requested")
}
except Exception as e:
logger.error("Health check failed", error=str(e))
return {
"status": "unhealthy",
"service": settings.SERVICE_NAME,
"version": settings.VERSION,
"database": "unknown",
"alert_service": {"status": "unknown"},
"error": str(e),
"timestamp": structlog.get_logger().info("Health check failed")
}
# Service info endpoint
@app.get(f"{settings.API_V1_STR}/info")
async def service_info():