@@ -51,14 +51,15 @@ local opts = cmsgpack.unpack(ARGV[3])
5151--- @include "includes/prepareJobForProcessing"
5252--- @include "includes/promoteDelayedJobs"
5353
54- local target , isPausedOrMaxed = getTargetQueueList (KEYS [9 ], activeKey , waitKey , KEYS [8 ])
54+ local target , isPausedOrMaxed , rateLimitMax , rateLimitDuration = getTargetQueueList (KEYS [9 ],
55+ activeKey , waitKey , KEYS [8 ])
5556
5657-- Check if there are delayed jobs that we can move to wait.
5758local markerKey = KEYS [11 ]
5859promoteDelayedJobs (delayedKey , markerKey , target , KEYS [3 ], eventStreamKey , ARGV [1 ],
5960 ARGV [2 ], KEYS [10 ], isPausedOrMaxed )
6061
61- local maxJobs = tonumber (opts [' limiter' ] and opts [' limiter' ][' max' ])
62+ local maxJobs = tonumber (rateLimitMax or ( opts [' limiter' ] and opts [' limiter' ][' max' ]) )
6263local expireTime = getRateLimitTTL (maxJobs , rateLimiterKey )
6364
6465-- Check if we are rate limited first.
@@ -67,6 +68,8 @@ if expireTime > 0 then return {0, 0, expireTime, 0} end
6768-- paused or maxed queue
6869if isPausedOrMaxed then return {0 , 0 , 0 , 0 } end
6970
71+ local limiterDuration = (opts [' limiter' ] and opts [' limiter' ][' duration' ]) or rateLimitDuration
72+
7073-- no job ID, try non-blocking move from wait to active
7174local jobId = rcall (" RPOPLPUSH" , waitKey , activeKey )
7275
7881
7982if jobId then
8083 return prepareJobForProcessing (ARGV [1 ], rateLimiterKey , eventStreamKey , jobId , ARGV [2 ],
81- maxJobs , markerKey , opts )
84+ maxJobs , limiterDuration , markerKey , opts )
8285else
8386 jobId = moveJobFromPrioritizedToActive (KEYS [3 ], activeKey , KEYS [10 ])
8487 if jobId then
8588 return prepareJobForProcessing (ARGV [1 ], rateLimiterKey , eventStreamKey , jobId , ARGV [2 ],
86- maxJobs , markerKey , opts )
89+ maxJobs , limiterDuration , markerKey , opts )
8790 end
8891end
8992
0 commit comments