import asyncio from contextlib import asynccontextmanager from fastapi import FastAPI from prometheus_fastapi_instrumentator import Instrumentator from .observability import setup_observability from .outbound.storage_factory import init_storage from .routers import media as media_router from .routers.api.main import api_router from .routers.bff.main import bff_router from .tasks.app import procrastinate_app @asynccontextmanager async def lifespan(app: FastAPI): async with procrastinate_app.open_async(): worker = asyncio.create_task( procrastinate_app.run_worker_async(install_signal_handlers=False) ) init_storage() setup_observability(app) yield app = FastAPI(title="Language Learning API", lifespan=lifespan) app.include_router(api_router) app.include_router(bff_router) app.include_router(media_router.router) Instrumentator().instrument(app).expose(app, should_gzip=True) @app.get("/health") async def health() -> dict: return {"status": "ok"}