QueuePause
Stopping a queue for a while because its downstream said “not now”, without ever making a stop that is already running shorter.
queue.rateLimit(ms) REPLACES what is there: BullMQ keeps one key per queue
for both the limiter’s window and a pause, and sets it with the new expiry.
Two refusals asking for different waits (fifteen minutes because a quota is
used up, one second because of a burst) leave whichever was written last,
so the short one cuts the long one.
So the time left is read first, from Redis through BullMQ’s
getRateLimitTtl (the key is shared by every replica and outlives a
restart), and the key is written only to make the stop longer. It is asked
with the worker’s max, which is how BullMQ tells a pause from a limiter
window that is merely open (it answers 0 for the second).
Read then write is two commands, and one worker runs several jobs at once,
so calls on one instance take turns. That is why there is exactly one
QueuePause per queue: the runtime builds it with the queue and every
worker of that queue shares it. Between two replicas the two commands can
still interleave; the worst case is a pause cut short, after which the next
refusal pauses the queue again.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new QueuePause(
queue,limiterMax):QueuePause
Parameters
Section titled “Parameters”Pick<Queue, "getRateLimitTtl" | "rateLimit">
limiterMax
Section titled “limiterMax”() => number
Returns
Section titled “Returns”QueuePause
Methods
Section titled “Methods”forAtLeast()
Section titled “forAtLeast()”forAtLeast(
ms):Promise<number>
Keeps the queue from handing out jobs for at least ms from now. Resolves
to how long it is stopped for: ms, or what is left of a longer stop.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”Promise<number>