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

gracefully retry getApplications when requests fail due to Ravello rate-limiting #194

Closed
ryran opened this issue May 30, 2018 · 1 comment
Assignees

Comments

@ryran
Copy link
Owner

ryran commented May 30, 2018

This manifests as HTTPError exceptions -- 429 client errors, e.g.:

$ ravshello -aDQ

>>> from __future__ import print_function
>>> from requests import HTTPError
>>> def getapps(c=1):
...     n = 0
...     now = datetime.now().strftime('%H:%M:%S')
...     print("[{}] Start time".format(now))
...     for i in range(c):
...             n += 1
...             try:
...                     apps = r.get_applications()
...             except HTTPError as e:
...                     now = datetime.now().strftime('%H:%M:%S')
...                     print("[{}] Failed getApplications call #{}".format(now, n))
...                     print(e[0])
...                     return
...             else:
...                     print("#{} ({} apps returned)".format(n, len(apps)))
...     now = datetime.now().strftime('%H:%M:%S')
...     print("[{}] End time".format(now))
...     print("Successfully called getApplications {} times".format(n))
... 
>>> getapps(15)
[17:54:19] Start time
#1 (57 apps returned)
#2 (57 apps returned)
#3 (57 apps returned)
#4 (57 apps returned)
#5 (57 apps returned)
#6 (57 apps returned)
#7 (57 apps returned)
#8 (57 apps returned)
#9 (57 apps returned)
#10 (57 apps returned)
[17:54:21] Failed getApplications call #11
429 Client Error: Too Many Requests for url: https://cloud.ravellosystems.com/api/v1/applications
>>> sleep(40); getapps(15)
[17:55:10] Start time
#1 (57 apps returned)
#2 (57 apps returned)
#3 (57 apps returned)
#4 (57 apps returned)
#5 (57 apps returned)
#6 (57 apps returned)
#7 (57 apps returned)
#8 (57 apps returned)
#9 (57 apps returned)
#10 (57 apps returned)
[17:55:11] Failed getApplications call #11
429 Client Error: Too Many Requests for url: https://cloud.ravellosystems.com/api/v1/applications

(On this account we have a 10/min limit on using getApplications.)

@ryran
Copy link
Owner Author

ryran commented May 31, 2018

For now, gonna handle this in the sdk, e.g.:

ryran/python-sdk@88568ed

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