File tree Expand file tree Collapse file tree 4 files changed +55
-0
lines changed
Expand file tree Collapse file tree 4 files changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { IApp } from '@plumber/types'
33import getTransferDetails from './common/get-transfer-details'
44import actions from './actions'
55import dynamicData from './dynamic-data'
6+ import queue from './queue'
67
78const app : IApp = {
89 name : 'Tiles' ,
@@ -17,6 +18,7 @@ const app: IApp = {
1718 actions,
1819 dynamicData,
1920 getTransferDetails,
21+ queue,
2022}
2123
2224export default app
Original file line number Diff line number Diff line change 1+ import type { IAppQueue } from '@plumber/types'
2+
3+ import { TILES_INTERVAL_BETWEEN_FIND_SINGLE_ROW_MS } from '@/config/app-env-vars/tiles'
4+ import Step from '@/models/step'
5+
6+ // Define actions that should be queued
7+ const QUEUED_ACTIONS = new Set ( [ 'findSingleRow' ] )
8+
9+ //
10+ // This config sets up a per-Tile findSingleRow action queue, i.e., only findSingleRow
11+ // actions are grouped and rate limited.
12+ // All other Tile actions are not grouped and do not need to be rate limited.
13+ //
14+ // This is necessary because the findSingleRow action is the most expensive
15+ // operation in the Tile app, due to the need to scan the entire DynamoDB table.
16+ //
17+
18+ const getGroupConfigForJob : IAppQueue [ 'getGroupConfigForJob' ] = async (
19+ jobData ,
20+ ) => {
21+ const step = await Step . query ( ) . findById ( jobData . stepId ) . throwIfNotFound ( )
22+ const tableId = step . parameters [ 'tableId' ] as string
23+
24+ if ( QUEUED_ACTIONS . has ( step . key ) ) {
25+ return {
26+ id : `${ tableId } -${ step . key } ` ,
27+ }
28+ }
29+
30+ // All other Tile actions are not grouped and do not need to be rate limited
31+ // as the write operations are fast and less expensive.
32+ return null
33+ }
34+
35+ const queueSettings = {
36+ getGroupConfigForJob,
37+ groupLimits : {
38+ type : 'concurrency' ,
39+ concurrency : 1 ,
40+ } ,
41+ isQueueDelayable : true ,
42+ queueRateLimit : {
43+ max : 1 ,
44+ duration : TILES_INTERVAL_BETWEEN_FIND_SINGLE_ROW_MS ,
45+ } ,
46+ } satisfies IAppQueue
47+
48+ export default queueSettings
Original file line number Diff line number Diff line change 2424import './m365'
2525import './formsg'
2626import './postman-sms'
27+ import './tiles'
Original file line number Diff line number Diff line change 1+ // Default to 1 action per second.
2+ export const TILES_INTERVAL_BETWEEN_FIND_SINGLE_ROW_MS = Number (
3+ process . env . TILES_INTERVAL_BETWEEN_FIND_SINGLE_ROW_MS ?? '1000' ,
4+ )
You can’t perform that action at this time.
0 commit comments