MCPcopy
hub / github.com/simstudioai/sim / executeWebhookJobInternal

Function executeWebhookJobInternal

apps/sim/background/webhook-execution.ts:354–716  ·  view source on GitHub ↗
(
  payload: WebhookExecutionPayload,
  correlation: AsyncExecutionCorrelation
)

Source from the content-addressed store, hash-verified

352}
353
354async function executeWebhookJobInternal(
355 payload: WebhookExecutionPayload,
356 correlation: AsyncExecutionCorrelation
357) {
358 const { executionId, requestId } = correlation
359 const loggingSession = new LoggingSession(
360 payload.workflowId,
361 executionId,
362 payload.provider,
363 requestId
364 )
365
366 const preprocessResult = await preprocessExecution({
367 workflowId: payload.workflowId,
368 userId: payload.userId,
369 triggerType: 'webhook',
370 executionId,
371 requestId,
372 triggerData: { correlation },
373 checkRateLimit: false,
374 checkDeployment: false,
375 skipUsageLimits: true,
376 workspaceId: payload.workspaceId,
377 loggingSession,
378 /**
379 * Reuse the route-resolved actor only for inline execution (set on the
380 * in-process payload). When absent — queued/Trigger.dev runs — preprocessing
381 * re-resolves the current billed account. Either way the ban and
382 * archived-workflow gates run fresh against the resolved actor.
383 */
384 resolvedActorUserId: payload.resolvedActorUserId,
385 })
386
387 if (!preprocessResult.success) {
388 throw new Error(preprocessResult.error?.message || 'Preprocessing failed in background job')
389 }
390
391 const { workflowRecord, executionTimeout } = preprocessResult
392 if (!workflowRecord) {
393 throw new Error(`Workflow ${payload.workflowId} not found during preprocessing`)
394 }
395
396 const workspaceId = workflowRecord.workspaceId
397 if (!workspaceId) {
398 throw new Error(`Workflow ${payload.workflowId} has no associated workspace`)
399 }
400
401 const workflowVariables = (workflowRecord.variables as Record<string, unknown>) || {}
402 const asyncTimeout = executionTimeout?.async ?? 120_000
403 const timeoutController = createTimeoutAbortController(asyncTimeout)
404
405 let deploymentVersionId: string | undefined
406
407 try {
408 const [workflowData, webhookRows, resolvedCredentialUserId] = await Promise.all([
409 loadDeployedWorkflowState(payload.workflowId, workspaceId),
410 db.select().from(webhook).where(eq(webhook.id, payload.webhookId)).limit(1),
411 payload.credentialId

Callers 1

runOperationFunction · 0.85

Calls 15

safeStartMethod · 0.95
safeCompleteMethod · 0.95
waitForPostExecutionMethod · 0.95
safeCompleteWithErrorMethod · 0.95
preprocessExecutionFunction · 0.90
getProviderHandlerFunction · 0.90
isTriggerValidFunction · 0.90
getBlockFunction · 0.90
getTriggerFunction · 0.90
safeAssignFunction · 0.90

Tested by

no test coverage detected