generated from coulomb/repo-seed
Implement ops-hub bootstrap compatibility
This commit is contained in:
@@ -1,17 +1,33 @@
|
||||
from collections.abc import AsyncIterator
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from fastapi import FastAPI
|
||||
|
||||
import core_hub.models # noqa: F401
|
||||
from core_hub import __version__
|
||||
from core_hub.api.v2 import router as api_v2_router
|
||||
from core_hub.config import get_settings
|
||||
from core_hub.db import Base, get_engine
|
||||
from core_hub.schemas import HealthResponse, ReadinessResponse
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(_: FastAPI) -> AsyncIterator[None]:
|
||||
settings = get_settings()
|
||||
if settings.auto_create_tables:
|
||||
engine = get_engine()
|
||||
async with engine.begin() as connection:
|
||||
await connection.run_sync(Base.metadata.create_all)
|
||||
yield
|
||||
|
||||
|
||||
def create_app() -> FastAPI:
|
||||
settings = get_settings()
|
||||
app = FastAPI(
|
||||
title="Core Hub API",
|
||||
version=__version__,
|
||||
description="Third-generation production interaction framework API.",
|
||||
lifespan=lifespan,
|
||||
)
|
||||
|
||||
@app.get("/healthz", response_model=HealthResponse, tags=["system"])
|
||||
|
||||
Reference in New Issue
Block a user