( workflowId: string, requestId: string )
| 50 | } |
| 51 | |
| 52 | async function cleanupExternalWebhooksForWorkflow( |
| 53 | workflowId: string, |
| 54 | requestId: string |
| 55 | ): Promise<void> { |
| 56 | try { |
| 57 | const { cleanupExternalWebhook } = await import('@/lib/webhooks/provider-subscriptions') |
| 58 | const webhooksToCleanup = await db |
| 59 | .select({ |
| 60 | webhook: webhook, |
| 61 | workflow: { |
| 62 | id: workflow.id, |
| 63 | userId: workflow.userId, |
| 64 | workspaceId: workflow.workspaceId, |
| 65 | }, |
| 66 | }) |
| 67 | .from(webhook) |
| 68 | .innerJoin(workflow, eq(webhook.workflowId, workflow.id)) |
| 69 | .where(eq(webhook.workflowId, workflowId)) |
| 70 | |
| 71 | for (const webhookData of webhooksToCleanup) { |
| 72 | try { |
| 73 | await cleanupExternalWebhook(webhookData.webhook, webhookData.workflow, requestId) |
| 74 | } catch (error) { |
| 75 | logger.warn( |
| 76 | `[${requestId}] Failed to cleanup external webhook ${webhookData.webhook.id} for workflow ${workflowId}`, |
| 77 | { error } |
| 78 | ) |
| 79 | } |
| 80 | } |
| 81 | } catch (error) { |
| 82 | logger.warn(`[${requestId}] Error during external webhook cleanup for workflow ${workflowId}`, { |
| 83 | error, |
| 84 | }) |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | export async function archiveWorkflow( |
| 89 | workflowId: string, |
no test coverage detected