feat: add bounded kafka ingestion pipeline

This commit is contained in:
2026-09-20 14:11:00 +03:30
parent 12cb9b3832
commit 89a746227b
11 changed files with 465 additions and 28 deletions

View File

@@ -1,22 +1,53 @@
from contextlib import asynccontextmanager
from fastapi import FastAPI
from core.api.kafka_publisher import KafkaPublisher
from core.api.publisher import Publisher
from core.api.routes import router
from core.config import get_settings
app = FastAPI(
title="Telecom CDR Ingestion API",
version="0.1.0",
)
def create_app(
publisher: Publisher | None = None,
) -> FastAPI:
@asynccontextmanager
async def lifespan(app: FastAPI):
active_publisher = publisher
if active_publisher is None:
active_publisher = KafkaPublisher(
get_settings()
)
app.state.publisher = active_publisher
await active_publisher.start()
try:
yield
finally:
await active_publisher.stop()
app = FastAPI(
title="Telecom CDR Ingestion API",
version="0.1.0",
lifespan=lifespan,
)
app.include_router(
router,
prefix="/api/v1",
)
@app.get("/health")
async def health() -> dict[str, str]:
return {
"status": "ok",
}
return app
app.include_router(
router,
prefix="/api/v1",
)
@app.get("/health")
async def health() -> dict[str, str]:
return {
"status": "ok",
}
app = create_app()