feat: fastapi app mit lifespan, webhook handler und /health
This commit is contained in:
41
app/main.py
Normal file
41
app/main.py
Normal file
@@ -0,0 +1,41 @@
|
||||
import logging
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from fastapi import FastAPI
|
||||
from qdrant_client import QdrantClient
|
||||
|
||||
from app.config import get_settings
|
||||
from app.ingest.embedder import embedding_dimension
|
||||
from app.logging_setup import setup_logging
|
||||
from app.qdrant_store import ensure_collection
|
||||
from app.webhook.handler import router as webhook_router
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def _startup_ensure_collection() -> None:
|
||||
settings = get_settings()
|
||||
dim = await embedding_dimension(settings.ollama_embed_model)
|
||||
client = QdrantClient(url=settings.qdrant_url)
|
||||
ensure_collection(client, settings.qdrant_collection, vector_size=dim)
|
||||
logger.info(
|
||||
"qdrant collection ready",
|
||||
extra={"event": "startup", "collection": settings.qdrant_collection, "dim": dim},
|
||||
)
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
setup_logging(get_settings().log_level)
|
||||
await _startup_ensure_collection()
|
||||
yield
|
||||
|
||||
|
||||
app = FastAPI(title="rag-ingestor", lifespan=lifespan)
|
||||
app.include_router(webhook_router)
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
async def health():
|
||||
return {"status": "ok"}
|
||||
Reference in New Issue
Block a user