language-learning-app/api/app/main.py
wilson 1a026e5056
Some checks are pending
/ test (push) Waiting to run
feat: add monitoring and instrumentation
2026-05-22 22:40:17 +01:00

38 lines
1 KiB
Python

import asyncio
from contextlib import asynccontextmanager
from prometheus_fastapi_instrumentator import Instrumentator
from .routers.api import generation, pos
from fastapi import FastAPI
from .routers.api import jobs
from .routers import media as media_router
from .routers.api.main import api_router
from .routers.bff.main import bff_router
from .outbound.storage_factory import init_storage
from .observability import setup_observability
from . import worker
@asynccontextmanager
async def lifespan(app: FastAPI):
init_storage()
setup_observability(app)
worker_task = asyncio.create_task(worker.worker_loop())
yield
worker_task.cancel()
try:
await worker_task
except asyncio.CancelledError:
pass
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"}