feat: create backend skeleton
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
from collections.abc import AsyncGenerator
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
import asyncpg
|
||||
from dishka.integrations.fastapi import FromDishka, inject, setup_dishka
|
||||
from fastapi import FastAPI
|
||||
|
||||
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.get("/health")
|
||||
@inject
|
||||
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)}
|
||||
|
||||
|
||||
setup_dishka(container, app)
|
||||
Reference in New Issue
Block a user