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

@retry should respect 429 Retry-After headers #238

Open
prkumar opened this issue Dec 29, 2021 Discussed in #235 · 2 comments
Open

@retry should respect 429 Retry-After headers #238

prkumar opened this issue Dec 29, 2021 Discussed in #235 · 2 comments

Comments

@prkumar
Copy link
Owner

prkumar commented Dec 29, 2021

Discussed in #235

Originally posted by mivade December 20, 2021
RFC 6585 describes the 429 status code to indicate hitting rate limits. This type of response may include a Retry-After header indicating the time in seconds to wait before trying again. Naively I would expect to be able to define my own backoff function to parse this header and yield that value to indicate how long to wait, but it looks like backoff functions have no knowledge of the response itself. Is there a way to get this functionality?

@prkumar
Copy link
Owner Author

prkumar commented Jan 5, 2022

prkumar added a commit that referenced this issue Jan 6, 2022
Adds a new base class, `uplink.retry.RetryBackoff`, which can be extended to implement custom backoff strategies. Subclasses can override three methods:

- `get_timeout_after_response(request, response)`: Returns the number of seconds to wait before retrying the request, or ``None`` to indicate that the given response should be returned.
- `get_timeout_after_exception(request, exc_type, exc_val, exc_tb)`: Returns the number of seconds to wait before retrying the request, or ``None`` to indicate that the given exception should be raised.
- `handle_after_final_retry()`: Handles any clean-up necessary following the final retry attempt.

An instance of a `RetryBackoff` subclass can be provided through the `backoff` argument of the `@retry` decorator.

#238
@prkumar prkumar mentioned this issue Jan 24, 2022
@prkumar
Copy link
Owner Author

prkumar commented Jan 24, 2022

The new RetryBackoff class is available now in v0.9.6!

@prkumar prkumar closed this as completed Jan 25, 2022
@prkumar prkumar reopened this Jan 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant