PyrateLimiter
PyrateLimiter copied to clipboard
[Feature Request] Add max_delay as an argument to try_acquire
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.
- 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.
- 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