(providerName: string)
| 6 | |
| 7 | /** Poll all active webhooks for a given provider. */ |
| 8 | export async function pollProvider(providerName: string): Promise<PollSummary> { |
| 9 | const handler = getPollingHandler(providerName) |
| 10 | if (!handler) { |
| 11 | throw new Error(`Unknown polling provider: ${providerName}`) |
| 12 | } |
| 13 | |
| 14 | const logger = createLogger(`${handler.label}PollingService`) |
| 15 | logger.info(`Starting ${handler.label} webhook polling`) |
| 16 | |
| 17 | const activeWebhooks = await fetchActiveWebhooks(handler.provider) |
| 18 | if (!activeWebhooks.length) { |
| 19 | logger.info(`No active ${handler.label} webhooks found`) |
| 20 | return { total: 0, successful: 0, failed: 0 } |
| 21 | } |
| 22 | |
| 23 | logger.info(`Found ${activeWebhooks.length} active ${handler.label} webhooks`) |
| 24 | |
| 25 | const { successCount, failureCount } = await runWithConcurrency( |
| 26 | activeWebhooks, |
| 27 | async (entry) => { |
| 28 | const requestId = generateShortId() |
| 29 | return handler.pollWebhook({ |
| 30 | webhookData: entry.webhook, |
| 31 | workflowData: entry.workflow, |
| 32 | requestId, |
| 33 | logger, |
| 34 | }) |
| 35 | }, |
| 36 | logger |
| 37 | ) |
| 38 | |
| 39 | const summary: PollSummary = { |
| 40 | total: activeWebhooks.length, |
| 41 | successful: successCount, |
| 42 | failed: failureCount, |
| 43 | } |
| 44 | logger.info(`${handler.label} polling completed`, summary) |
| 45 | return summary |
| 46 | } |
no test coverage detected