language-learning-app/api/app/main.py

36 lines
865 B
Python

import asyncio
from contextlib import asynccontextmanager
from fastapi import FastAPI
from .routers import pos, generation, jobs
from .routers import auth as auth_router
from .routers import media as media_router
from .storage import ensure_bucket_exists
from . import worker
@asynccontextmanager
async def lifespan(app: FastAPI):
ensure_bucket_exists()
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(auth_router.router)
app.include_router(pos.router)
app.include_router(generation.router)
app.include_router(jobs.router)
app.include_router(media_router.router)
@app.get("/health")
async def health() -> dict:
return {"status": "ok"}