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

Function executeWorkflowJob

apps/sim/background/workflow-execution.ts:58–205  ·  view source on GitHub ↗
(payload: WorkflowExecutionPayload)

Source from the content-addressed store, hash-verified

56 * @see executeWorkflowCore For the core workflow execution logic
57 */
58export async function executeWorkflowJob(payload: WorkflowExecutionPayload) {
59 const workflowId = payload.workflowId
60 const correlation = buildWorkflowCorrelation(payload)
61 const executionId = correlation.executionId
62 const requestId = correlation.requestId
63
64 return runWithRequestContext({ requestId }, async () => {
65 logger.info(`[${requestId}] Starting workflow execution job: ${workflowId}`, {
66 userId: payload.userId,
67 triggerType: payload.triggerType,
68 executionId,
69 })
70
71 const triggerType = (correlation.triggerType || 'api') as CoreTriggerType
72 const loggingSession = new LoggingSession(workflowId, executionId, triggerType, requestId)
73
74 try {
75 const preprocessResult = await preprocessExecution({
76 workflowId: payload.workflowId,
77 userId: payload.userId,
78 triggerType: triggerType,
79 executionId: executionId,
80 requestId: requestId,
81 checkRateLimit: true,
82 checkDeployment: true,
83 loggingSession: loggingSession,
84 triggerData: { correlation },
85 })
86
87 if (!preprocessResult.success) {
88 logger.error(`[${requestId}] Preprocessing failed: ${preprocessResult.error?.message}`, {
89 workflowId,
90 statusCode: preprocessResult.error?.statusCode,
91 })
92
93 throw new Error(preprocessResult.error?.message || 'Preprocessing failed')
94 }
95
96 const actorUserId = preprocessResult.actorUserId!
97 const workspaceId = preprocessResult.workflowRecord?.workspaceId
98 if (!workspaceId) {
99 throw new Error(`Workflow ${workflowId} has no associated workspace`)
100 }
101
102 logger.info(`[${requestId}] Preprocessing passed. Using actor: ${actorUserId}`)
103
104 const workflow = preprocessResult.workflowRecord!
105
106 const metadata: ExecutionMetadata = {
107 requestId,
108 executionId,
109 workflowId,
110 workspaceId,
111 userId: actorUserId,
112 sessionUserId: undefined,
113 workflowUserId: workflow.userId,
114 triggerType: payload.triggerType || 'api',
115 useDraftState: false,

Calls 15

markAsFailedMethod · 0.95
waitForPostExecutionMethod · 0.95
safeCompleteWithErrorMethod · 0.95
runWithRequestContextFunction · 0.90
preprocessExecutionFunction · 0.90
executeWorkflowCoreFunction · 0.90
getTimeoutErrorMessageFunction · 0.90
toErrorFunction · 0.90
hasExecutionResultFunction · 0.90

Tested by

no test coverage detected