Rate limiter per job name
See original GitHub issueWant to explore the possibility to rate limit a queue based on the job name. This would be a worker-level config which would enable applying a rate limiter to specific job names. This would be similar to the groupKey
but would remove the need to pass an extra groupKey param in job data, the job name itself would act as the groupKey. I like this because it centralizes the rate limit implementation to solely the worker, doesn’t matter what is passed as job data as long as the job name is correct.
My thoughts are something along these lines:
const worker = new Worker("myQueue", async job => {
switch (job.name) {
case "limitedJob": {
// rate limited
break;
}
case "normalJob": {
// no rate limiting applied
break;
}
default:
}
},
{
limiter: {
jobs: {
// this key indicates the job name to be limited
limitedJob: {
// same rate limit config as usual
max: 30,
duration: 1000
}
}
}
}
);
Happy to look into implementing this myself if it’s a possibility!
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Rate limiting - BullMQ
The rate limiter is global, so if you have for example 10 workers for one queue with the above settings, still only 10...
Read more >Laravel 8 Job Rate Limiter that can be used without Redis
Laravel 8 Job Rate Limiter that can be used without Redis - AppServiceProvider.php.
Read more >A job middleware to rate limit jobs - Freek.dev
Introducing laravel-rate-limited-job-middleware You can use the RateLimited middleware by letting the middleware method of your job return it. ...
Read more >Rate Limiting - Laravel - The PHP Framework For Web Artisans
The Illuminate\Support\Facades\RateLimiter facade may be used to interact with the rate limiter. The simplest method offered by the rate limiter is the attempt ......
Read more >Announcing Rate Limiting for .NET - Microsoft Developer Blogs
Rate limiting is the concept of limiting how much a resource can be accessed. For example, you know that a database your application ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Here is a code snippet that I have in my project:
I can use it as:
The only limitation, that duration is in seconds.
As an alternative to implementing this into BullMQ, a separate limiter might be useful, such as https://github.com/microlinkhq/async-ratelimiter.
The core feature of any limiter is just
await delay(X)
where X depends on previous calls, so it’s possible to write a simple wrapper around the job handler that will wait a correspondent amount of time (0 if it’s under the limit). Or, a wrapper that will reschedule the job with the right delay (if BullMQ allows it)