Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request allows Bee-Queue to integrate with any non-blocking external limiter library to throttle jobs. Recently I have been using Bottleneck to force jobs to wait until they are ready to run, but that ties up my concurrency and sometimes nothing runs. This is a much better solution!
PR includes:
Queue.process
takes a function as an optional second argument, which if provided will be run just prior to executing each job. This allows you to query an external limiter and optionally reschedule the job if it is not cleared to run. The limiter query function helps the queue rapidly scan for jobs which are ready to run rather than tying up your concurrency with waiting jobs.The limiter query function can use a callback or return a promise. The promise should resolve to an object which at minimum contains a boolean
ready
parameter,true
if the job is ready to run.Additionally if the limiter check promise rejects or passes an error to the callback the job will be immediately failed with no retry logic.