Skip to content

Commit eec7c4e

Browse files
committed
chore: create aisay specific queue
1 parent fb1b687 commit eec7c4e

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import '@/apps'
2+
3+
import { afterEach, describe, expect, it, vi } from 'vitest'
4+
5+
import aisayApp from '..'
6+
7+
const mocks = vi.hoisted(() => ({
8+
stepQueryResult: vi.fn(),
9+
}))
10+
11+
vi.mock('@/models/step', () => ({
12+
default: {
13+
query: vi.fn(() => ({
14+
findById: vi.fn(() => ({
15+
throwIfNotFound: mocks.stepQueryResult,
16+
})),
17+
})),
18+
},
19+
}))
20+
21+
describe('AISAY Queue', () => {
22+
afterEach(() => {
23+
vi.restoreAllMocks()
24+
})
25+
26+
it('sets group ID to the connection ID', async () => {
27+
mocks.stepQueryResult.mockResolvedValueOnce({
28+
connectionId: 'mock-connection-id',
29+
key: 'useGeneralisedModel',
30+
appKey: 'aisay',
31+
})
32+
const groupConfig = await aisayApp.queue.getGroupConfigForJob({
33+
flowId: 'test-flow-id',
34+
stepId: 'test-step-id',
35+
executionId: 'test-step-id',
36+
})
37+
expect(groupConfig).toEqual({
38+
id: 'mock-connection-id',
39+
})
40+
})
41+
42+
it('sets group concurrency to 1', () => {
43+
expect(aisayApp.queue.groupLimits).toEqual({
44+
type: 'concurrency',
45+
concurrency: 1,
46+
})
47+
})
48+
})

packages/backend/src/apps/aisay/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { IApp } from '@plumber/types'
22

33
import actions from './actions'
44
import auth from './auth'
5+
import queue from './queue'
56

67
const app: IApp = {
78
name: 'AISAY',
@@ -20,6 +21,7 @@ const app: IApp = {
2021
settingsStepLabel: 'Set up step',
2122
addConnectionLabel: 'Add new AISAY connection',
2223
},
24+
queue,
2325
}
2426

2527
export default app
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import type { IAppQueue } from '@plumber/types'
2+
3+
import Step from '@/models/step'
4+
5+
const getGroupConfigForJob: IAppQueue['getGroupConfigForJob'] = async (
6+
jobData,
7+
) => {
8+
const step = await Step.query().findById(jobData.stepId).throwIfNotFound()
9+
10+
/**
11+
* This config sets up a per-AISAY connection queue, i.e., all AISAY actions
12+
* that use the same AISAY connection are grouped together and rate limited.
13+
* This is a conservative approach to start with and can be tweaked later.
14+
*/
15+
return {
16+
id: step.connectionId,
17+
}
18+
}
19+
20+
const queueSettings = {
21+
getGroupConfigForJob,
22+
groupLimits: {
23+
type: 'concurrency',
24+
concurrency: 1,
25+
},
26+
isQueueDelayable: false,
27+
} satisfies IAppQueue
28+
29+
export default queueSettings

0 commit comments

Comments
 (0)