mirror of
https://github.com/aljazceru/enclava.git
synced 2025-12-17 23:44:24 +01:00
mega changes
This commit is contained in:
@@ -59,7 +59,10 @@ async def _check_redis_startup():
|
||||
duration = time.perf_counter() - start
|
||||
logger.info(
|
||||
"Startup Redis check succeeded",
|
||||
extra={"redis_url": settings.REDIS_URL, "duration_seconds": round(duration, 3)},
|
||||
extra={
|
||||
"redis_url": settings.REDIS_URL,
|
||||
"duration_seconds": round(duration, 3),
|
||||
},
|
||||
)
|
||||
except Exception as exc: # noqa: BLE001
|
||||
logger.warning(
|
||||
@@ -104,9 +107,10 @@ async def lifespan(app: FastAPI):
|
||||
"""
|
||||
logger.info("Starting Enclava platform...")
|
||||
background_tasks = []
|
||||
|
||||
|
||||
# Initialize core cache service (before database to provide caching for auth)
|
||||
from app.core.cache import core_cache
|
||||
|
||||
try:
|
||||
await core_cache.initialize()
|
||||
logger.info("Core cache service initialized successfully")
|
||||
@@ -122,12 +126,13 @@ async def lifespan(app: FastAPI):
|
||||
|
||||
# Initialize database
|
||||
await init_db()
|
||||
|
||||
|
||||
# Initialize config manager
|
||||
await init_config_manager()
|
||||
|
||||
# Ensure platform permissions are registered before module discovery
|
||||
from app.services.permission_manager import permission_registry
|
||||
|
||||
permission_registry.register_platform_permissions()
|
||||
|
||||
# Initialize LLM service (needed by RAG module) concurrently
|
||||
@@ -153,40 +158,45 @@ async def lifespan(app: FastAPI):
|
||||
await module_manager.initialize(app)
|
||||
app.state.module_manager = module_manager
|
||||
logger.info("Module manager initialized successfully")
|
||||
|
||||
|
||||
# Initialize document processor
|
||||
from app.services.document_processor import document_processor
|
||||
|
||||
try:
|
||||
await document_processor.start()
|
||||
app.state.document_processor = document_processor
|
||||
except Exception as exc:
|
||||
logger.error(f"Document processor failed to start: {exc}")
|
||||
app.state.document_processor = None
|
||||
|
||||
|
||||
# Setup metrics
|
||||
try:
|
||||
setup_metrics(app)
|
||||
except Exception as exc:
|
||||
logger.warning(f"Metrics setup failed: {exc}")
|
||||
|
||||
|
||||
# Start background audit worker
|
||||
from app.services.audit_service import start_audit_worker
|
||||
|
||||
try:
|
||||
start_audit_worker()
|
||||
except Exception as exc:
|
||||
logger.warning(f"Audit worker failed to start: {exc}")
|
||||
|
||||
|
||||
# Initialize plugin auto-discovery service concurrently
|
||||
async def initialize_plugins():
|
||||
from app.services.plugin_autodiscovery import initialize_plugin_autodiscovery
|
||||
|
||||
try:
|
||||
discovery_results = await initialize_plugin_autodiscovery()
|
||||
app.state.plugin_discovery_results = discovery_results
|
||||
logger.info(f"Plugin auto-discovery completed: {discovery_results.get('summary')}")
|
||||
logger.info(
|
||||
f"Plugin auto-discovery completed: {discovery_results.get('summary')}"
|
||||
)
|
||||
except Exception as exc:
|
||||
logger.warning(f"Plugin auto-discovery failed: {exc}")
|
||||
app.state.plugin_discovery_results = {"error": str(exc)}
|
||||
|
||||
|
||||
background_tasks.append(asyncio.create_task(initialize_plugins()))
|
||||
|
||||
if background_tasks:
|
||||
@@ -194,9 +204,9 @@ async def lifespan(app: FastAPI):
|
||||
for result in results:
|
||||
if isinstance(result, Exception):
|
||||
logger.warning(f"Background startup task failed: {result}")
|
||||
|
||||
|
||||
logger.info("Platform started successfully")
|
||||
|
||||
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
@@ -205,6 +215,7 @@ async def lifespan(app: FastAPI):
|
||||
|
||||
# Cleanup embedding service HTTP sessions
|
||||
from app.services.embedding_service import embedding_service
|
||||
|
||||
try:
|
||||
await embedding_service.cleanup()
|
||||
logger.info("Embedding service cleaned up successfully")
|
||||
@@ -213,14 +224,16 @@ async def lifespan(app: FastAPI):
|
||||
|
||||
# Close core cache service
|
||||
from app.core.cache import core_cache
|
||||
|
||||
await core_cache.cleanup()
|
||||
|
||||
# Close Redis connection for cached API key service
|
||||
from app.services.cached_api_key import cached_api_key_service
|
||||
|
||||
await cached_api_key_service.close()
|
||||
|
||||
# Stop document processor
|
||||
processor = getattr(app.state, 'document_processor', None)
|
||||
processor = getattr(app.state, "document_processor", None)
|
||||
if processor:
|
||||
await processor.stop()
|
||||
|
||||
@@ -297,10 +310,12 @@ async def validation_exception_handler(request, exc: RequestValidationError):
|
||||
"type": error.get("type", ""),
|
||||
"location": error.get("loc", []),
|
||||
"message": error.get("msg", ""),
|
||||
"input": str(error.get("input", "")) if error.get("input") is not None else None
|
||||
"input": str(error.get("input", ""))
|
||||
if error.get("input") is not None
|
||||
else None,
|
||||
}
|
||||
errors.append(error_dict)
|
||||
|
||||
|
||||
return JSONResponse(
|
||||
status_code=422,
|
||||
content={
|
||||
@@ -326,7 +341,7 @@ async def general_exception_handler(request, exc: Exception):
|
||||
# Include Internal API routes (for frontend)
|
||||
app.include_router(internal_api_router, prefix="/api-internal/v1")
|
||||
|
||||
# Include Public API routes (for external clients)
|
||||
# Include Public API routes (for external clients)
|
||||
app.include_router(public_api_router, prefix="/api/v1")
|
||||
|
||||
# OpenAI-compatible routes are now included in public API router at /api/v1/
|
||||
@@ -357,7 +372,7 @@ async def root():
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
|
||||
|
||||
uvicorn.run(
|
||||
"app.main:app",
|
||||
host=settings.APP_HOST,
|
||||
|
||||
Reference in New Issue
Block a user