Add role-based filtering and imporve code

This commit is contained in:
Urtzi Alfaro
2025-10-15 16:12:49 +02:00
parent 96ad5c6692
commit 8f9e9a7edc
158 changed files with 11033 additions and 1544 deletions

View File

@@ -9,14 +9,14 @@ from fastapi.responses import JSONResponse
import structlog
from contextlib import asynccontextmanager
from app.core import settings, DatabaseManager, RedisClient
from app.core import settings, DatabaseManager
from app.api import demo_sessions, demo_accounts, demo_operations
from shared.redis_utils import initialize_redis, close_redis
logger = structlog.get_logger()
# Initialize database and redis
# Initialize database
db_manager = DatabaseManager()
redis_client = RedisClient()
@asynccontextmanager
@@ -27,8 +27,12 @@ async def lifespan(app: FastAPI):
# Initialize database
db_manager.initialize()
# Connect to Redis
await redis_client.connect()
# Initialize Redis using shared implementation
await initialize_redis(
redis_url=settings.REDIS_URL,
db=0,
max_connections=50
)
logger.info("Demo Session Service started successfully")
@@ -36,7 +40,7 @@ async def lifespan(app: FastAPI):
# Cleanup on shutdown
await db_manager.close()
await redis_client.close()
await close_redis()
logger.info("Demo Session Service stopped")
@@ -92,7 +96,10 @@ async def root():
@app.get("/health")
async def health():
"""Health check endpoint"""
redis_ok = await redis_client.ping()
from shared.redis_utils import get_redis_manager
redis_manager = await get_redis_manager()
redis_ok = await redis_manager.health_check()
return {
"status": "healthy" if redis_ok else "degraded",