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

Function handleAsyncExecution

apps/sim/app/api/workflows/[id]/execute/route.ts:260–347  ·  view source on GitHub ↗
(params: AsyncExecutionParams)

Source from the content-addressed store, hash-verified

258}
259
260async function handleAsyncExecution(params: AsyncExecutionParams): Promise<NextResponse> {
261 const { requestId, workflowId, userId, workspaceId, input, triggerType, executionId, callChain } =
262 params
263 const asyncLogger = logger.withMetadata({
264 requestId,
265 workflowId,
266 workspaceId,
267 userId,
268 executionId,
269 })
270
271 const correlation = {
272 executionId,
273 requestId,
274 source: 'workflow' as const,
275 workflowId,
276 triggerType,
277 }
278
279 const payload: WorkflowExecutionPayload = {
280 workflowId,
281 userId,
282 workspaceId,
283 input,
284 triggerType,
285 executionId,
286 requestId,
287 correlation,
288 callChain,
289 executionMode: 'async',
290 }
291
292 try {
293 const jobQueue = await getJobQueue()
294 const jobId = await jobQueue.enqueue('workflow-execution', payload, {
295 metadata: { workflowId, workspaceId, userId, correlation },
296 })
297
298 asyncLogger.info('Queued async workflow execution', { jobId })
299
300 if (shouldExecuteInline()) {
301 void (async () => {
302 try {
303 await jobQueue.startJob(jobId)
304 const output = await executeWorkflowJob(payload)
305 await jobQueue.completeJob(jobId, output)
306 } catch (error) {
307 const errorMessage = toError(error).message
308 asyncLogger.error('Async workflow execution failed', {
309 jobId,
310 error: errorMessage,
311 })
312 // Release the reserved slot in case the job never reached
313 // executeWorkflowJob (e.g. startJob threw) and thus never finalized a
314 // LoggingSession to free it. Idempotent: a no-op when the job already
315 // finalized and released.
316 await releaseExecutionSlot(executionId)
317 try {

Callers 1

handleExecutePostFunction · 0.85

Calls 13

getJobQueueFunction · 0.90
shouldExecuteInlineFunction · 0.90
executeWorkflowJobFunction · 0.90
toErrorFunction · 0.90
releaseExecutionSlotFunction · 0.90
getBaseUrlFunction · 0.90
infoMethod · 0.80
errorMethod · 0.80
enqueueMethod · 0.65
startJobMethod · 0.65
completeJobMethod · 0.65
markJobFailedMethod · 0.65

Tested by

no test coverage detected