forked from erp-dev/erp
28 lines
884 B
Python
28 lines
884 B
Python
import logging
|
|
|
|
from celery import shared_task
|
|
|
|
from notifier.services import dispatch_notification_event
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@shared_task(bind=True)
|
|
def dispatch_notification_event_task(self, *, event_key: str, merchant_id: int, payload: dict | None = None) -> dict:
|
|
results = dispatch_notification_event(
|
|
event_key=event_key,
|
|
merchant_id=merchant_id,
|
|
payload=payload or {},
|
|
)
|
|
summary = {
|
|
"task_id": self.request.id,
|
|
"event_key": event_key,
|
|
"merchant_id": merchant_id,
|
|
"total_count": len(results),
|
|
"sent_count": sum(1 for item in results if item.get("status") == "sent"),
|
|
"failed_count": sum(1 for item in results if item.get("status") == "failed"),
|
|
"results": results,
|
|
}
|
|
logger.info("[notifier.tasks] notification task finished: %s", summary)
|
|
return summary
|