Skip to content

Commit f31bc71

Browse files
committed
fix(hitl): async resume
1 parent 3e85218 commit f31bc71

File tree

1 file changed

+19
-12
lines changed
  • apps/sim/app/api/resume/[workflowId]/[executionId]/[contextId]

1 file changed

+19
-12
lines changed

apps/sim/app/api/resume/[workflowId]/[executionId]/[contextId]/route.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getJobQueue, shouldUseBullMQ } from '@/lib/core/async-jobs'
55
import { createBullMQJobData } from '@/lib/core/bullmq'
66
import { generateRequestId } from '@/lib/core/utils/request'
77
import { SSE_HEADERS } from '@/lib/core/utils/sse'
8+
import { getBaseUrl } from '@/lib/core/utils/urls'
89
import { generateId } from '@/lib/core/utils/uuid'
910
import { enqueueWorkspaceDispatch } from '@/lib/core/workspace-dispatch'
1011
import { setExecutionMeta } from '@/lib/execution/event-buffer'
@@ -224,10 +225,11 @@ export async function POST(
224225
parentExecutionId: executionId,
225226
}
226227

228+
let jobId: string
227229
try {
228230
const useBullMQ = shouldUseBullMQ()
229231
if (useBullMQ) {
230-
await enqueueWorkspaceDispatch({
232+
jobId = await enqueueWorkspaceDispatch({
231233
id: enqueueResult.resumeExecutionId,
232234
workspaceId: workflow.workspaceId,
233235
lane: 'runtime',
@@ -241,28 +243,33 @@ export async function POST(
241243
})
242244
} else {
243245
const jobQueue = await getJobQueue()
244-
const jobId = await jobQueue.enqueue('resume-execution', resumePayload, {
246+
jobId = await jobQueue.enqueue('resume-execution', resumePayload, {
245247
metadata: { workflowId, workspaceId: workflow.workspaceId, userId },
246248
})
247-
logger.info('Enqueued resume execution job', {
248-
jobId,
249-
resumeExecutionId: enqueueResult.resumeExecutionId,
250-
})
251249
}
250+
logger.info('Enqueued async resume execution', {
251+
jobId,
252+
resumeExecutionId: enqueueResult.resumeExecutionId,
253+
})
252254
} catch (dispatchError) {
253-
logger.error('Failed to dispatch async resume, falling back to in-process', {
255+
logger.error('Failed to dispatch async resume execution', {
254256
error: dispatchError instanceof Error ? dispatchError.message : String(dispatchError),
257+
resumeExecutionId: enqueueResult.resumeExecutionId,
255258
})
256-
PauseResumeManager.startResumeExecution(resumeArgs).catch((error) => {
257-
logger.error('Fallback resume execution also failed', { error })
258-
})
259+
return NextResponse.json(
260+
{ error: 'Failed to queue resume execution. Please try again.' },
261+
{ status: 503 }
262+
)
259263
}
260264

261265
return NextResponse.json(
262266
{
263-
status: 'started',
267+
success: true,
268+
async: true,
269+
jobId,
264270
executionId: enqueueResult.resumeExecutionId,
265-
message: 'Resume execution started asynchronously.',
271+
message: 'Resume execution queued',
272+
statusUrl: `${getBaseUrl()}/api/jobs/${jobId}`,
266273
},
267274
{ status: 202 }
268275
)

0 commit comments

Comments
 (0)