This commit is contained in:
2026-11-22 17:20:34 +03:00
parent c10bf08feb
commit 7e1780be67
14 changed files with 938 additions and 60 deletions
+9 -1
View File
@@ -10,7 +10,8 @@ from fastapi.exceptions import RequestValidationError
from fastapi.responses import JSONResponse
from starlette.exceptions import HTTPException as StarletteHTTPException
from .config import load_object_settings, load_settings
from .broker import Broker
from .config import load_broker_url, load_object_settings, load_settings
from .db import open_pool
from .errors import ApiError
from .objects import ObjectStore
@@ -58,8 +59,14 @@ _OPENAPI_PATH = Path(__file__).resolve().parents[1] / 'contracts' / 'openapi.jso
async def lifespan(app: FastAPI):
"""Migrations are not applied here: the one-shot migrate service runs them before replicas start."""
settings = load_settings()
# The client logs can echo the AMQP URL. Leave them off.
logging.getLogger('aio_pika').setLevel(logging.ERROR)
logging.getLogger('aiormq').setLevel(logging.ERROR)
pool = await open_pool(settings.database_url)
broker = Broker(load_broker_url())
try:
await broker.connect()
app.state.broker = broker
app.state.store = Store(
pool,
settings.session_ttl_seconds,
@@ -69,6 +76,7 @@ async def lifespan(app: FastAPI):
logger.info('instance %s started', settings.instance_id)
yield
finally:
await broker.close()
await pool.close()