feat: integrate HttpClientManager and CacheService into lifespan
This commit is contained in:
@@ -15,6 +15,8 @@ from .pypi_proxy import router as pypi_router
|
|||||||
from .seed import seed_database
|
from .seed import seed_database
|
||||||
from .auth import create_default_admin
|
from .auth import create_default_admin
|
||||||
from .rate_limit import limiter
|
from .rate_limit import limiter
|
||||||
|
from .http_client import HttpClientManager
|
||||||
|
from .cache_service import CacheService
|
||||||
|
|
||||||
settings = get_settings()
|
settings = get_settings()
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
@@ -38,6 +40,17 @@ async def lifespan(app: FastAPI):
|
|||||||
finally:
|
finally:
|
||||||
db.close()
|
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
|
# Seed test data in development mode
|
||||||
if settings.is_development:
|
if settings.is_development:
|
||||||
logger.info(f"Running in {settings.env} mode - checking for seed data")
|
logger.info(f"Running in {settings.env} mode - checking for seed data")
|
||||||
@@ -51,6 +64,12 @@ async def lifespan(app: FastAPI):
|
|||||||
|
|
||||||
yield
|
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(
|
app = FastAPI(
|
||||||
title="Orchard",
|
title="Orchard",
|
||||||
|
|||||||
Reference in New Issue
Block a user