Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/sim/app/api/chat/[identifier]/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ vi.mock('@/lib/workflows/streaming/streaming', () => ({
createStreamingResponse: vi.fn().mockImplementation(async () => createMockStream()),
}))

vi.mock('@/lib/workflows/executor/execute-workflow', () => ({
executeWorkflow: vi.fn().mockResolvedValue({ success: true, output: {} }),
}))

vi.mock('@/lib/core/utils/sse', () => ({
SSE_HEADERS: {
'Content-Type': 'text/event-stream',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getJobQueue, shouldUseBullMQ } from '@/lib/core/async-jobs'
import { createBullMQJobData } from '@/lib/core/bullmq'
import { generateRequestId } from '@/lib/core/utils/request'
import { SSE_HEADERS } from '@/lib/core/utils/sse'
import { getBaseUrl } from '@/lib/core/utils/urls'
import { generateId } from '@/lib/core/utils/uuid'
import { enqueueWorkspaceDispatch } from '@/lib/core/workspace-dispatch'
import { setExecutionMeta } from '@/lib/execution/event-buffer'
Expand Down Expand Up @@ -224,10 +225,11 @@ export async function POST(
parentExecutionId: executionId,
}

let jobId: string
try {
const useBullMQ = shouldUseBullMQ()
if (useBullMQ) {
await enqueueWorkspaceDispatch({
jobId = await enqueueWorkspaceDispatch({
id: enqueueResult.resumeExecutionId,
workspaceId: workflow.workspaceId,
lane: 'runtime',
Expand All @@ -241,28 +243,33 @@ export async function POST(
})
} else {
const jobQueue = await getJobQueue()
const jobId = await jobQueue.enqueue('resume-execution', resumePayload, {
jobId = await jobQueue.enqueue('resume-execution', resumePayload, {
metadata: { workflowId, workspaceId: workflow.workspaceId, userId },
})
logger.info('Enqueued resume execution job', {
jobId,
resumeExecutionId: enqueueResult.resumeExecutionId,
})
}
logger.info('Enqueued async resume execution', {
jobId,
resumeExecutionId: enqueueResult.resumeExecutionId,
})
} catch (dispatchError) {
logger.error('Failed to dispatch async resume, falling back to in-process', {
logger.error('Failed to dispatch async resume execution', {
error: dispatchError instanceof Error ? dispatchError.message : String(dispatchError),
resumeExecutionId: enqueueResult.resumeExecutionId,
})
PauseResumeManager.startResumeExecution(resumeArgs).catch((error) => {
logger.error('Fallback resume execution also failed', { error })
})
return NextResponse.json(
{ error: 'Failed to queue resume execution. Please try again.' },
{ status: 503 }
)
}

return NextResponse.json(
{
status: 'started',
success: true,
async: true,
jobId,
executionId: enqueueResult.resumeExecutionId,
message: 'Resume execution started asynchronously.',
message: 'Resume execution queued',
statusUrl: `${getBaseUrl()}/api/jobs/${jobId}`,
},
{ status: 202 }
)
Expand Down
Loading