MCPcopy Index your code
hub / github.com/simstudioai/sim / cleanupWebhooksForWorkflow

Function cleanupWebhooksForWorkflow

apps/sim/lib/webhooks/deploy.ts:970–1071  ·  view source on GitHub ↗
(
  workflowId: string,
  workflow: Record<string, unknown>,
  requestId: string,
  deploymentVersionId?: string | null,
  skipExternalCleanup = false,
  strictExternalCleanup = false,
  shouldDeleteWebhook?: () => Promise<boolean>
)

Source from the content-addressed store, hash-verified

968 * makes this probe non-authoritative.
969 */
970export async function cleanupWebhooksForWorkflow(
971 workflowId: string,
972 workflow: Record<string, unknown>,
973 requestId: string,
974 deploymentVersionId?: string | null,
975 skipExternalCleanup = false,
976 strictExternalCleanup = false,
977 shouldDeleteWebhook?: () => Promise<boolean>
978): Promise<void> {
979 const existingWebhooks = await db
980 .select()
981 .from(webhook)
982 .where(
983 deploymentVersionId
984 ? and(
985 eq(webhook.workflowId, workflowId),
986 eq(webhook.deploymentVersionId, deploymentVersionId),
987 isNull(webhook.archivedAt)
988 )
989 : deploymentVersionId === null
990 ? and(
991 eq(webhook.workflowId, workflowId),
992 isNull(webhook.deploymentVersionId),
993 isNull(webhook.archivedAt)
994 )
995 : and(eq(webhook.workflowId, workflowId), isNull(webhook.archivedAt))
996 )
997
998 if (existingWebhooks.length === 0) {
999 return
1000 }
1001
1002 logger.info(
1003 `[${requestId}] Cleaning up ${existingWebhooks.length} webhook(s) for ${skipExternalCleanup ? 'DB records only' : 'undeploy'}`,
1004 {
1005 workflowId,
1006 deploymentVersionId,
1007 webhookIds: existingWebhooks.map((wh) => wh.id),
1008 }
1009 )
1010
1011 if (!skipExternalCleanup) {
1012 for (const wh of existingWebhooks) {
1013 if (shouldDeleteWebhook && !(await shouldDeleteWebhook())) {
1014 logger.info(`[${requestId}] Stopping webhook cleanup because deployment became active`, {
1015 workflowId,
1016 deploymentVersionId,
1017 webhookId: wh.id,
1018 })
1019 return
1020 }
1021
1022 try {
1023 await cleanupExternalWebhook(wh, workflow, requestId, {
1024 throwOnError: strictExternalCleanup,
1025 })
1026 } catch (cleanupError) {
1027 logger.warn(`[${requestId}] Failed to cleanup external webhook ${wh.id}`, cleanupError)

Calls 5

cleanupExternalWebhookFunction · 0.90
infoMethod · 0.80
warnMethod · 0.65
eqFunction · 0.50

Tested by

no test coverage detected