feat: add bounded kafka ingestion pipeline
This commit is contained in:
@@ -3,6 +3,7 @@ import json
|
||||
from fastapi import APIRouter, Request, status
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from core.api.publisher import IngestionQueueFull, KafkaPublishError
|
||||
from core.domain.errors import CDRProcessingError
|
||||
from core.domain.validation import parse_raw_cdr
|
||||
|
||||
@@ -49,6 +50,30 @@ async def ingest_raw_cdr(request: Request) -> JSONResponse:
|
||||
},
|
||||
)
|
||||
|
||||
try:
|
||||
await request.app.state.publisher.publish(
|
||||
payload,
|
||||
key=raw_cdr.raw_id,
|
||||
)
|
||||
|
||||
except IngestionQueueFull:
|
||||
return JSONResponse(
|
||||
status_code=status.HTTP_429_TOO_MANY_REQUESTS,
|
||||
content={
|
||||
"error": "backpressure",
|
||||
"detail": "Ingestion queue is full.",
|
||||
},
|
||||
)
|
||||
|
||||
except KafkaPublishError as exc:
|
||||
return JSONResponse(
|
||||
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
|
||||
content={
|
||||
"error": "kafka_unavailable",
|
||||
"detail": str(exc),
|
||||
},
|
||||
)
|
||||
|
||||
return JSONResponse(
|
||||
status_code=status.HTTP_202_ACCEPTED,
|
||||
content={
|
||||
|
||||
Reference in New Issue
Block a user