Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/docs: getRateLimitTtl needs more details #2628

Closed
yashmasani opened this issue Jun 30, 2024 · 0 comments · Fixed by #2631
Closed

feature/docs: getRateLimitTtl needs more details #2628

yashmasani opened this issue Jun 30, 2024 · 0 comments · Fixed by #2631
Labels
bug Something isn't working

Comments

@yashmasani
Copy link

yashmasani commented Jun 30, 2024

Is your feature request related to a problem? Please describe.

Since I have limited resources, I need to send 429 when the queue is being rate limited i.e when the set limit has been passed.

for example, I needed a function to help me write something like this:

let ttl = await queue.getRateLimitTtl();
if (ttl > 0) {
  res.writeHead(429).end();
}

Initially, from reading the docs, I thought the function mentioned in the docs queue.getRateLimitTtl() returns the ttl once the number of jobs have passed the limit that was initially set. Similar to the function getRateLimitTTL within the lua script here

This led to some confusion on my end when I started hitting 429 very often within the endpoint.

After having a deeper look, it seems like queue.getRateLimitTtl() shows ttl > 0 after a single job has been added to the queue within the duration.
Perhaps more clarification is need to be reflected with the docs
Also, maybe this is just me, but I fail to see the use case of the current behaviour of queue.getRateLimitTtl()

Describe the solution you'd like

  • A new class function for queue that is similar to the function getRateLimitTTL within the lua script here
    ( get ttl if and only if max jobs has been passed else 0)
  • update docs to reflect the difference between the two functions

Describe alternatives you've considered

I think I could run the lua script to get the ttl but I prefer if it was done gracefully via a class function in bullmq

If there any obvious alternatives I did not consider, sorry about that, I am fairly new to bullmq

@yashmasani yashmasani changed the title getRateLimitTtl feature/docs: getRateLimitTtl needs more details Jun 30, 2024
@roggervalf roggervalf added the bug Something isn't working label Jul 2, 2024
github-actions bot pushed a commit that referenced this issue Jul 5, 2024
## [5.8.4](v5.8.3...v5.8.4) (2024-07-05)

### Bug Fixes

* **queue-getters:** consider passing maxJobs when calling getRateLimitTtl ([#2631](#2631)) fixes [#2628](#2628) ([9f6609a](9f6609a))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants