From 146ca2ad74b4bb4e1348884cf7c6bd0d4ca01068 Mon Sep 17 00:00:00 2001 From: Mondo Diaz Date: Wed, 4 Feb 2026 09:45:09 -0600 Subject: [PATCH] feat: integrate HttpClientManager and CacheService into lifespan --- backend/app/main.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/backend/app/main.py b/backend/app/main.py index 6d99f89..78ad43a 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -15,6 +15,8 @@ from .pypi_proxy import router as pypi_router from .seed import seed_database from .auth import create_default_admin from .rate_limit import limiter +from .http_client import HttpClientManager +from .cache_service import CacheService settings = get_settings() logging.basicConfig(level=logging.INFO) @@ -38,6 +40,17 @@ async def lifespan(app: FastAPI): finally: db.close() + # Initialize infrastructure services + logger.info("Initializing infrastructure services...") + + app.state.http_client = HttpClientManager(settings) + await app.state.http_client.startup() + + app.state.cache = CacheService(settings) + await app.state.cache.startup() + + logger.info("Infrastructure services ready") + # Seed test data in development mode if settings.is_development: logger.info(f"Running in {settings.env} mode - checking for seed data") @@ -51,6 +64,12 @@ async def lifespan(app: FastAPI): yield + # Shutdown infrastructure services + logger.info("Shutting down infrastructure services...") + await app.state.http_client.shutdown() + await app.state.cache.shutdown() + logger.info("Shutdown complete") + app = FastAPI( title="Orchard",