Public entry point. Schedules webhook delivery as a background task. Args: event_name: The event that occurred (e.g. "course_completed"). org_id: The organization where the event happened. data: Event-specific payload data. webhook_ids: If provided, only del
(
event_name: str,
org_id: int,
data: dict,
webhook_ids: Optional[List[int]] = None,
)
| 71 | |
| 72 | |
| 73 | async def dispatch_webhooks( |
| 74 | event_name: str, |
| 75 | org_id: int, |
| 76 | data: dict, |
| 77 | webhook_ids: Optional[List[int]] = None, |
| 78 | ) -> None: |
| 79 | """ |
| 80 | Public entry point. Schedules webhook delivery as a background task. |
| 81 | |
| 82 | Args: |
| 83 | event_name: The event that occurred (e.g. "course_completed"). |
| 84 | org_id: The organization where the event happened. |
| 85 | data: Event-specific payload data. |
| 86 | webhook_ids: If provided, only deliver to these specific endpoints |
| 87 | (used by the test/ping feature). |
| 88 | """ |
| 89 | validate_event_data(event_name, data) |
| 90 | task = asyncio.create_task( |
| 91 | _deliver_webhooks(event_name, org_id, data, webhook_ids) |
| 92 | ) |
| 93 | _background_tasks.add(task) |
| 94 | task.add_done_callback(_background_tasks.discard) |
| 95 | task.add_done_callback( |
| 96 | lambda t: logger.error("Webhook delivery batch failed: %s", t.exception()) |
| 97 | if not t.cancelled() and t.exception() else None |
| 98 | ) |
| 99 | |
| 100 | |
| 101 | async def _deliver_webhooks( |
no test coverage detected