feat(contract): add opt-in MAX configuration and lifecycle
CI / ruff · pytest (pull_request) Successful in 2m24s

Refs #81
This commit is contained in:
Pavel Eliseev
2026-10-04 15:58:25 +03:00
parent bde6ec6855
commit b3e103954f
4 changed files with 108 additions and 7 deletions
+18 -6
View File
@@ -30,13 +30,25 @@ async def lifespan(_: FastAPI) -> AsyncGenerator[None, None]:
# In compose Postgres is required and healthy before the app starts; this branch is for running the
# API (and its tests) without a database. Endpoints touching the DB will fail until it is reachable.
log.error("db init failed, continuing without db: %s", type(exc).__name__)
if settings.max_enabled:
raise # MAX requires persistent bindings and a delivery queue.
# Lanes fill these in (#13, #11); main.py itself stays frozen (#34).
await scheduler.start()
await telegram.start()
yield
await telegram.stop()
await scheduler.stop()
await dispose()
max_channel = None
try:
await telegram.start()
if settings.max_enabled:
from app.channels import max_bot
max_channel = max_bot
await max_channel.start()
await scheduler.start()
yield
finally:
await scheduler.stop()
if max_channel is not None:
await max_channel.stop()
await telegram.stop()
await dispose()
app = FastAPI(title="PTSRaiAgent API", version="0.1.0", lifespan=lifespan)