Skip to content

Commit 016a0d2

Browse files
committed
feat: add WORKER_CURRENCY config
1 parent f591167 commit 016a0d2

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const WORKER_CONCURRENCY = {
2+
'm365-excel': 3,
3+
postman: 3,
4+
'postman-sms': 3,
5+
slack: 3,
6+
'telegram-bot': 3,
7+
tiles: 3,
8+
}

packages/backend/src/workers/action.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { makeActionWorker } from '@/workers/helpers/make-action-worker'
1414

1515
// Worker for our main action queue
1616
export const mainActionWorker = makeActionWorker({
17+
appKey: MAIN_ACTION_QUEUE_NAME,
1718
queueName: MAIN_ACTION_QUEUE_NAME,
1819
redisConnectionPrefix: MAIN_ACTION_QUEUE_REDIS_CONNECTION_PREFIX,
1920
queueConfig: {
@@ -32,6 +33,7 @@ for (const [appKey, app] of Object.entries(apps)) {
3233
}
3334

3435
appActionWorkers[appKey] = makeActionWorker({
36+
appKey,
3537
queueName: appActionQueues[appKey].name,
3638
queueConfig: app.queue,
3739
})

packages/backend/src/workers/helpers/make-action-worker.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88

99
import appConfig from '@/config/app'
1010
import { createRedisClient } from '@/config/redis'
11+
import { WORKER_CONCURRENCY } from '@/config/workers'
1112
import { handleFailedStepAndThrow } from '@/helpers/actions'
1213
import { exponentialBackoffWithJitter } from '@/helpers/backoff'
1314
import {
@@ -30,12 +31,16 @@ import { processAction } from '@/services/action'
3031
function convertParamsToBullMqOptions(
3132
params: MakeActionWorkerParams,
3233
) /* inferred type */ {
33-
const { queueName, redisConnectionPrefix, queueConfig } = params
34+
const { appKey, queueName, redisConnectionPrefix, queueConfig } = params
3435
const { isQueueDelayable, queueRateLimit } = queueConfig
3536

37+
const concurrency =
38+
WORKER_CONCURRENCY[appKey as keyof typeof WORKER_CONCURRENCY] ||
39+
appConfig.workerActionConcurrency
40+
3641
const workerOptions: WorkerProOptions = {
3742
connection: createRedisClient(),
38-
concurrency: appConfig.workerActionConcurrency,
43+
concurrency,
3944
settings: {
4045
backoffStrategy: exponentialBackoffWithJitter,
4146
},
@@ -74,6 +79,7 @@ function convertParamsToBullMqOptions(
7479
}
7580

7681
interface MakeActionWorkerParams {
82+
appKey: string
7783
queueName: string
7884
redisConnectionPrefix?: string
7985
queueConfig: IAppQueue

0 commit comments

Comments
 (0)