Skip to content

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

@ryran

Description

@ryran

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.)

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions