language-learning-app/api/app/main.py
2026-05-18 21:18:19 +01:00

36 lines
857 B
Python

import asyncio
from contextlib import asynccontextmanager
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 . import worker
@asynccontextmanager
async def lifespan(app: FastAPI):
init_storage()
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)
@app.get("/health")
async def health() -> dict:
return {"status": "ok"}