-
Notifications
You must be signed in to change notification settings - Fork 3.5k
feat(concurrency): bullmq based concurrency control system #3605
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e0389ba
feat(concurrency): bullmq based queueing system
icecrasher321 75eac74
fix bun lock
icecrasher321 be83c97
remove manual execs off queues
icecrasher321 74de331
address comments
icecrasher321 7eab00b
fix legacy team limits
icecrasher321 d5fbc3c
cleanup enterprise typing code
icecrasher321 8ee4c59
inline child triggers
icecrasher321 41e1c9c
fix status check
icecrasher321 7bf9526
address more comments
icecrasher321 9a6886c
optimize reconciler scan
icecrasher321 2bf1feb
remove dead code
icecrasher321 9d5ca6b
Merge staging and resolve document-processor conflict
icecrasher321 9612066
add to landing page
icecrasher321 b2ae9db
Merge branch 'staging' into feat/conc-control
icecrasher321 53733e4
Add load testing framework
4a77f72
Merge branch 'staging' into feat/conc-control
icecrasher321 9477964
update bullmq
icecrasher321 7f021de
Merge branch 'feat/conc-control' of github.com:simstudioai/sim into f…
icecrasher321 8ef37a4
fix
icecrasher321 ebf687c
fix headless path
icecrasher321 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| /** | ||
| * @vitest-environment node | ||
| */ | ||
| import type { NextRequest } from 'next/server' | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
|
||
| const { | ||
| mockCheckHybridAuth, | ||
| mockGetDispatchJobRecord, | ||
| mockGetJobQueue, | ||
| mockVerifyWorkflowAccess, | ||
| mockGetWorkflowById, | ||
| } = vi.hoisted(() => ({ | ||
| mockCheckHybridAuth: vi.fn(), | ||
| mockGetDispatchJobRecord: vi.fn(), | ||
| mockGetJobQueue: vi.fn(), | ||
| mockVerifyWorkflowAccess: vi.fn(), | ||
| mockGetWorkflowById: vi.fn(), | ||
| })) | ||
|
|
||
| vi.mock('@sim/logger', () => ({ | ||
| createLogger: () => ({ | ||
| info: vi.fn(), | ||
| warn: vi.fn(), | ||
| error: vi.fn(), | ||
| debug: vi.fn(), | ||
| }), | ||
| })) | ||
|
|
||
| vi.mock('@/lib/auth/hybrid', () => ({ | ||
| checkHybridAuth: mockCheckHybridAuth, | ||
| })) | ||
|
|
||
| vi.mock('@/lib/core/async-jobs', () => ({ | ||
| JOB_STATUS: { | ||
| PENDING: 'pending', | ||
| PROCESSING: 'processing', | ||
| COMPLETED: 'completed', | ||
| FAILED: 'failed', | ||
| }, | ||
| getJobQueue: mockGetJobQueue, | ||
| })) | ||
|
|
||
| vi.mock('@/lib/core/workspace-dispatch/store', () => ({ | ||
| getDispatchJobRecord: mockGetDispatchJobRecord, | ||
| })) | ||
|
|
||
| vi.mock('@/lib/core/utils/request', () => ({ | ||
| generateRequestId: vi.fn().mockReturnValue('request-1'), | ||
| })) | ||
|
|
||
| vi.mock('@/socket/middleware/permissions', () => ({ | ||
| verifyWorkflowAccess: mockVerifyWorkflowAccess, | ||
| })) | ||
|
|
||
| vi.mock('@/lib/workflows/utils', () => ({ | ||
| getWorkflowById: mockGetWorkflowById, | ||
| })) | ||
|
|
||
| import { GET } from './route' | ||
|
|
||
| function createMockRequest(): NextRequest { | ||
| return { | ||
| headers: { | ||
| get: () => null, | ||
| }, | ||
| } as NextRequest | ||
| } | ||
|
|
||
| describe('GET /api/jobs/[jobId]', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
|
|
||
| mockCheckHybridAuth.mockResolvedValue({ | ||
| success: true, | ||
| userId: 'user-1', | ||
| apiKeyType: undefined, | ||
| workspaceId: undefined, | ||
| }) | ||
|
|
||
| mockVerifyWorkflowAccess.mockResolvedValue({ hasAccess: true }) | ||
| mockGetWorkflowById.mockResolvedValue({ | ||
| id: 'workflow-1', | ||
| workspaceId: 'workspace-1', | ||
| }) | ||
|
|
||
| mockGetJobQueue.mockResolvedValue({ | ||
| getJob: vi.fn().mockResolvedValue(null), | ||
| }) | ||
| }) | ||
|
|
||
| it('returns dispatcher-aware waiting status with metadata', async () => { | ||
| mockGetDispatchJobRecord.mockResolvedValue({ | ||
| id: 'dispatch-1', | ||
| workspaceId: 'workspace-1', | ||
| lane: 'runtime', | ||
| queueName: 'workflow-execution', | ||
| bullmqJobName: 'workflow-execution', | ||
| bullmqPayload: {}, | ||
| metadata: { | ||
| workflowId: 'workflow-1', | ||
| }, | ||
| priority: 10, | ||
| status: 'waiting', | ||
| createdAt: 1000, | ||
| admittedAt: 2000, | ||
| }) | ||
|
|
||
| const response = await GET(createMockRequest(), { | ||
| params: Promise.resolve({ jobId: 'dispatch-1' }), | ||
| }) | ||
| const body = await response.json() | ||
|
|
||
| expect(response.status).toBe(200) | ||
| expect(body.status).toBe('waiting') | ||
| expect(body.metadata.queueName).toBe('workflow-execution') | ||
| expect(body.metadata.lane).toBe('runtime') | ||
| expect(body.metadata.workspaceId).toBe('workspace-1') | ||
| }) | ||
|
|
||
| it('returns completed output from dispatch state', async () => { | ||
| mockGetDispatchJobRecord.mockResolvedValue({ | ||
| id: 'dispatch-2', | ||
| workspaceId: 'workspace-1', | ||
| lane: 'interactive', | ||
| queueName: 'workflow-execution', | ||
| bullmqJobName: 'direct-workflow-execution', | ||
| bullmqPayload: {}, | ||
| metadata: { | ||
| workflowId: 'workflow-1', | ||
| }, | ||
| priority: 1, | ||
| status: 'completed', | ||
| createdAt: 1000, | ||
| startedAt: 2000, | ||
| completedAt: 7000, | ||
| output: { success: true }, | ||
| }) | ||
|
|
||
| const response = await GET(createMockRequest(), { | ||
| params: Promise.resolve({ jobId: 'dispatch-2' }), | ||
| }) | ||
| const body = await response.json() | ||
|
|
||
| expect(response.status).toBe(200) | ||
| expect(body.status).toBe('completed') | ||
| expect(body.output).toEqual({ success: true }) | ||
| expect(body.metadata.duration).toBe(5000) | ||
| }) | ||
|
|
||
| it('returns 404 when neither dispatch nor BullMQ job exists', async () => { | ||
| mockGetDispatchJobRecord.mockResolvedValue(null) | ||
|
|
||
| const response = await GET(createMockRequest(), { | ||
| params: Promise.resolve({ jobId: 'missing-job' }), | ||
| }) | ||
|
|
||
| expect(response.status).toBe(404) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.