Загрузить файлы в «alert-receiver/app»

This commit is contained in:
2026-08-06 18:31:13 +03:00
parent 5c5938e68c
commit 4b122dfee7
5 changed files with 291 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
from __future__ import annotations
import logging
import httpx
from app.config import settings
from app.models import ProcessorForwardEnvelope
logger = logging.getLogger(__name__)
async def forward_to_processor(envelope: ProcessorForwardEnvelope) -> bool:
if not settings.forward_to_processor:
logger.info(
"Forwarding disabled, event accepted locally only: correlation_id=%s",
envelope.event.correlation_id,
)
return False
headers = {}
if settings.alert_processor_token:
headers["X-Internal-Token"] = settings.alert_processor_token
try:
async with httpx.AsyncClient(timeout=settings.forward_timeout_seconds) as client:
response = await client.post(
settings.alert_processor_url,
json=envelope.model_dump(mode="json"),
headers=headers,
)
response.raise_for_status()
logger.info(
"Forwarded event to alert-processor: correlation_id=%s status=%s",
envelope.event.correlation_id,
response.status_code,
)
return True
except Exception as exc:
logger.exception(
"Failed to forward event to alert-processor: correlation_id=%s error=%s",
envelope.event.correlation_id,
exc,
)
return False