-
Notifications
You must be signed in to change notification settings - Fork 63
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
Add a retry
decorator
#102
Comments
This is similar to #71 |
Here's my original reply. It would be nice if Uplink supported usage of existing decorators for retry, rate-limiting, etc. At the moment, this is not possible (because of how consumer methods are implemented). It might be worth it to consider if and how we should support this usage. |
An additional use case for this sort of functionality is when auth tokens have a short expiry. On some (admittedly not great) API's I catch an expired token as an exception, refresh it and then try the original request again. Being able to simplify that interaction would be awesome. |
@bendews You should look into https://github.com/oauthlib/oauthlib and https://requests-oauthlib.readthedocs.io/en/latest/ |
@liiight - the from requests_oauthlib from OAuth2Session
session = OAuth2Session(client_id)
github = GitHub(base_url=BASE_URL, client=session) Is this what you're talking about? |
Exactly, thanks for pointing that out. |
@liiight I would have had far less sleepless nights if they were OAuth compliant, trust me on that! 😁 |
The
Here's some documentation for the decorator. (I'll also be soon adding a section to the quickstart about this feature). Notably, this decorator can be used like the other decorators, such as class GitHub(uplink.Consumer):
@uplink.retry(max_attempts=2)
@uplink.get("/users/{user}")
def get_user(self, user):
pass If you get the chance to try it out, let me know if you also have any feedback! |
I just released an new alpha version,
Also, I've added a section to the quickstart to help get started with using this decorator: https://uplink.readthedocs.io/en/latest/user/quickstart.html#retrying |
I haven't had a chance to play with this but the interface look great. One suggestion though, you could use native ptrhon status code enum for the retry conditions: https://docs.python.org/3/library/http.html#http.HTTPStatus |
@liiight - Thanks for the suggestion! I'll add a way to use status codes in the retry condition. |
Here's the original use case from @liiight on Gitter:
The text was updated successfully, but these errors were encountered: