Merge branch 'main' into cursor/implement-usage-based-subscription-and-monitoring-0179
This commit is contained in:
@@ -12,6 +12,7 @@ from collections import defaultdict
|
||||
from loguru import logger
|
||||
from dotenv import load_dotenv
|
||||
import asyncio
|
||||
from datetime import datetime
|
||||
from middleware.monitoring_middleware import monitoring_middleware
|
||||
|
||||
# Load environment variables
|
||||
@@ -60,6 +61,10 @@ from routers.linkedin import router as linkedin_router
|
||||
# Import LinkedIn image generation router
|
||||
from api.linkedin_image_generation import router as linkedin_image_router
|
||||
|
||||
# Import hallucination detector router
|
||||
from api.hallucination_detector import router as hallucination_detector_router
|
||||
from api.writing_assistant import router as writing_assistant_router
|
||||
|
||||
# Import user data endpoints
|
||||
# Import content planning endpoints
|
||||
from api.content_planning.api.router import router as content_planning_router
|
||||
@@ -174,6 +179,62 @@ async def health():
|
||||
"""Health check endpoint."""
|
||||
return health_check()
|
||||
|
||||
@app.get("/health/database")
|
||||
async def database_health_check():
|
||||
"""Database health check endpoint including persona tables verification."""
|
||||
try:
|
||||
from services.database import get_db_session
|
||||
from models.persona_models import WritingPersona, PlatformPersona, PersonaAnalysisResult, PersonaValidationResult
|
||||
|
||||
session = get_db_session()
|
||||
if not session:
|
||||
return {"status": "error", "message": "Could not get database session"}
|
||||
|
||||
# Test all persona tables
|
||||
tables_status = {}
|
||||
try:
|
||||
session.query(WritingPersona).first()
|
||||
tables_status["writing_personas"] = "ok"
|
||||
except Exception as e:
|
||||
tables_status["writing_personas"] = f"error: {str(e)}"
|
||||
|
||||
try:
|
||||
session.query(PlatformPersona).first()
|
||||
tables_status["platform_personas"] = "ok"
|
||||
except Exception as e:
|
||||
tables_status["platform_personas"] = f"error: {str(e)}"
|
||||
|
||||
try:
|
||||
session.query(PersonaAnalysisResult).first()
|
||||
tables_status["persona_analysis_results"] = "ok"
|
||||
except Exception as e:
|
||||
tables_status["persona_analysis_results"] = f"error: {str(e)}"
|
||||
|
||||
try:
|
||||
session.query(PersonaValidationResult).first()
|
||||
tables_status["persona_validation_results"] = "ok"
|
||||
except Exception as e:
|
||||
tables_status["persona_validation_results"] = f"error: {str(e)}"
|
||||
|
||||
session.close()
|
||||
|
||||
# Check if all tables are ok
|
||||
all_ok = all(status == "ok" for status in tables_status.values())
|
||||
|
||||
return {
|
||||
"status": "healthy" if all_ok else "warning",
|
||||
"message": "Database connection successful" if all_ok else "Some persona tables may have issues",
|
||||
"persona_tables": tables_status,
|
||||
"timestamp": datetime.utcnow().isoformat()
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
return {
|
||||
"status": "error",
|
||||
"message": f"Database health check failed: {str(e)}",
|
||||
"timestamp": datetime.utcnow().isoformat()
|
||||
}
|
||||
|
||||
# Onboarding status endpoints
|
||||
@app.get("/api/onboarding/status")
|
||||
async def onboarding_status():
|
||||
@@ -386,6 +447,10 @@ app.include_router(linkedin_router)
|
||||
# Include LinkedIn image generation router
|
||||
app.include_router(linkedin_image_router)
|
||||
|
||||
# Include hallucination detector router
|
||||
app.include_router(hallucination_detector_router)
|
||||
app.include_router(writing_assistant_router)
|
||||
|
||||
# Include user data router
|
||||
# Include content planning router
|
||||
app.include_router(content_planning_router)
|
||||
|
||||
Reference in New Issue
Block a user