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 Request] Add max_delay as an argument to try_acquire #178

Open
lordscales91 opened this issue Aug 9, 2024 · 0 comments
Open

[Feature Request] Add max_delay as an argument to try_acquire #178

lordscales91 opened this issue Aug 9, 2024 · 0 comments

Comments

@lordscales91
Copy link

Hi there! I would like to have a max_delay argument on try_acquire that will take precedence over the max_delay value on the Limiter instance.

I have a use case where I would like to set different maximum delays when trying to put an item depending on the context. I have a scheduled job that is calling a rate-limited API, but there are some URL endpoints on my web that also need to call that same API. The API in question allows 60 requests per minute.

  1. The scheduled job is extracting some data, computing some values with it and storing it on the database. I don't want to drop any requests while doing this, so I set the maximum delay to 1 minute.
  2. When calling the API from the web endpoint, I don't want to have the user wait over a minute, I would like to set it to 5 seconds or so. If it cannot be done in 5 seconds (either because there are several users accessing that URL or because the job is running) I want to error and inform the user that this information cannot be obtained at the moment and suggest them to try it later.

The problem is that currently I cannot do that easily because the max_delay is initialized when instantiating the Limiter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant