SSE endpoint and the quest-completed transition (#154)

This commit was merged in pull request #154.
This commit is contained in:
2026-09-22 23:08:03 -04:00
parent 550a8b3e1e
commit a07ce1b2f2
5 changed files with 438 additions and 0 deletions
+5
View File
@@ -39,6 +39,7 @@ from fastapi import FastAPI
from api.config import ApiConfig
from api.database import DatabaseState, make_database
from api.events import TransitionPublisher
from api.routes_panel import router as panel_router
@@ -47,12 +48,16 @@ def _build_lifespan(db_path: str):
Captured as a closure so the app factory can hand the configured
path in without threading it through FastAPI's lifespan signature.
The lifespan also installs the app's ONE in-process transition
publisher on ``app.state.publisher`` (see :mod:`api.events`) so
every route and SSE subscriber shares that single instance.
"""
@asynccontextmanager
async def lifespan(app: FastAPI) -> AsyncIterator[None]:
state = make_database(db_path)
app.state.db = state
app.state.publisher = TransitionPublisher()
try:
await state.open_and_migrate()
yield