forked from erp-dev/erp
feat: notifier beta
This commit is contained in:
27
notifier/tasks.py
Normal file
27
notifier/tasks.py
Normal file
@@ -0,0 +1,27 @@
|
||||
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
|
||||
Reference in New Issue
Block a user