New alert service

This commit is contained in:
Urtzi Alfaro
2025-12-05 20:07:01 +01:00
parent 1fe3a73549
commit 667e6e0404
393 changed files with 26002 additions and 61033 deletions

View File

@@ -410,14 +410,65 @@ async def receive_webhook(
logger.info("Duplicate webhook ignored", event_id=event_id)
return _get_webhook_response(pos_system, success=True)
# TODO: Queue for async processing if needed
# For now, mark as received and ready for processing
processing_duration_ms = int((datetime.utcnow() - start_time).total_seconds() * 1000)
await webhook_service.update_webhook_status(
webhook_log.id,
status="queued",
processing_duration_ms=processing_duration_ms
)
# Queue for async processing via RabbitMQ
try:
from shared.messaging import get_rabbitmq_client
import uuid as uuid_module
rabbitmq_client = get_rabbitmq_client()
if rabbitmq_client:
# Publish POS transaction event for async processing
event_payload = {
"event_id": str(uuid_module.uuid4()),
"event_type": f"pos.{webhook_type}",
"timestamp": datetime.utcnow().isoformat(),
"tenant_id": str(tenant_id) if tenant_id else None,
"data": {
"webhook_log_id": str(webhook_log.id),
"pos_system": pos_system,
"webhook_type": webhook_type,
"payload": webhook_data,
"event_id": event_id
}
}
await rabbitmq_client.publish_event(
exchange_name="pos.events",
routing_key=f"pos.{webhook_type}",
event_data=event_payload
)
logger.info("POS transaction queued for async processing",
event_id=event_payload["event_id"],
webhook_log_id=str(webhook_log.id))
# Update status to queued
processing_duration_ms = int((datetime.utcnow() - start_time).total_seconds() * 1000)
await webhook_service.update_webhook_status(
webhook_log.id,
status="queued",
processing_duration_ms=processing_duration_ms
)
else:
logger.warning("RabbitMQ client not available, marking as received only")
processing_duration_ms = int((datetime.utcnow() - start_time).total_seconds() * 1000)
await webhook_service.update_webhook_status(
webhook_log.id,
status="received",
processing_duration_ms=processing_duration_ms
)
except Exception as queue_error:
logger.error("Failed to queue POS transaction for async processing",
error=str(queue_error),
webhook_log_id=str(webhook_log.id))
# Mark as received even if queuing fails
processing_duration_ms = int((datetime.utcnow() - start_time).total_seconds() * 1000)
await webhook_service.update_webhook_status(
webhook_log.id,
status="received",
processing_duration_ms=processing_duration_ms
)
logger.info("Webhook processed and queued successfully",
pos_system=pos_system,