36 lines
1004 B
Python
36 lines
1004 B
Python
from collections.abc import AsyncGenerator
|
|
from contextlib import asynccontextmanager
|
|
|
|
import asyncpg
|
|
from dishka.integrations.fastapi import DishkaRoute, FromDishka, setup_dishka
|
|
from fastapi import FastAPI
|
|
|
|
from api.routers import backfill, folders, policy
|
|
from dependencies.container import container
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app_: FastAPI) -> AsyncGenerator[None]:
|
|
yield
|
|
await app_.state.dishka_container.close()
|
|
|
|
|
|
app = FastAPI(title="beavergram API", lifespan=lifespan)
|
|
app.router.route_class = DishkaRoute
|
|
|
|
|
|
@app.get("/health")
|
|
async def health(pool: FromDishka[asyncpg.Pool]) -> dict[str, bool]:
|
|
db_ok = await pool.fetchval("SELECT 1") == 1
|
|
timescale_ok = await pool.fetchval(
|
|
"SELECT EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'timescaledb')"
|
|
)
|
|
return {"db": db_ok, "timescaledb": bool(timescale_ok)}
|
|
|
|
|
|
app.include_router(policy.router)
|
|
app.include_router(folders.router)
|
|
app.include_router(backfill.router)
|
|
|
|
setup_dishka(container, app)
|