@@ -5,6 +5,7 @@ import { getJobQueue, shouldUseBullMQ } from '@/lib/core/async-jobs'
55import { createBullMQJobData } from '@/lib/core/bullmq'
66import { generateRequestId } from '@/lib/core/utils/request'
77import { SSE_HEADERS } from '@/lib/core/utils/sse'
8+ import { getBaseUrl } from '@/lib/core/utils/urls'
89import { generateId } from '@/lib/core/utils/uuid'
910import { enqueueWorkspaceDispatch } from '@/lib/core/workspace-dispatch'
1011import { 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