* Deletes a webhook record unless the deployment became active again. * * `shouldDeleteWebhook` is awaited BEFORE the transaction opens — its * implementations query the global pool, so running it inside the * transaction would nest a second pooled checkout under the held * connection. The tran
(params: {
workflowId: string
deploymentVersionId?: string | null
webhookId: string
shouldDeleteWebhook?: () => Promise<boolean>
})
| 1081 | * aborts the delete if the version was reactivated. |
| 1082 | */ |
| 1083 | async function deleteWebhookRecordAfterCleanup(params: { |
| 1084 | workflowId: string |
| 1085 | deploymentVersionId?: string | null |
| 1086 | webhookId: string |
| 1087 | shouldDeleteWebhook?: () => Promise<boolean> |
| 1088 | }): Promise<boolean> { |
| 1089 | if (params.shouldDeleteWebhook && !(await params.shouldDeleteWebhook())) { |
| 1090 | return false |
| 1091 | } |
| 1092 | |
| 1093 | if (!params.shouldDeleteWebhook || typeof params.deploymentVersionId !== 'string') { |
| 1094 | await db |
| 1095 | .delete(webhook) |
| 1096 | .where(and(eq(webhook.workflowId, params.workflowId), eq(webhook.id, params.webhookId))) |
| 1097 | return true |
| 1098 | } |
| 1099 | |
| 1100 | const deploymentVersionId = params.deploymentVersionId |
| 1101 | |
| 1102 | return db.transaction(async (tx) => { |
| 1103 | const [inactiveVersion] = await tx |
| 1104 | .select({ id: workflowDeploymentVersion.id }) |
| 1105 | .from(workflowDeploymentVersion) |
| 1106 | .where( |
| 1107 | and( |
| 1108 | eq(workflowDeploymentVersion.workflowId, params.workflowId), |
| 1109 | eq(workflowDeploymentVersion.id, deploymentVersionId), |
| 1110 | eq(workflowDeploymentVersion.isActive, false) |
| 1111 | ) |
| 1112 | ) |
| 1113 | .limit(1) |
| 1114 | .for('update') |
| 1115 | |
| 1116 | if (!inactiveVersion) return false |
| 1117 | |
| 1118 | await tx |
| 1119 | .delete(webhook) |
| 1120 | .where( |
| 1121 | and( |
| 1122 | eq(webhook.workflowId, params.workflowId), |
| 1123 | eq(webhook.id, params.webhookId), |
| 1124 | eq(webhook.deploymentVersionId, deploymentVersionId) |
| 1125 | ) |
| 1126 | ) |
| 1127 | return true |
| 1128 | }) |
| 1129 | } |
no test coverage detected