1
0
mirror of https://github.com/github/octodns.git synced 2024-05-11 05:55:00 +00:00

Python 3 friendly way to re-raise when tries expire

This commit is contained in:
Ross McFarland
2019-12-10 12:20:25 -08:00
parent f0bc9add22
commit ea2a52c307

View File

@@ -31,17 +31,18 @@ class Ns1Client(object):
def _try(self, method, *args, **kwargs):
tries = self.retry_count
while tries:
while True: # We'll raise to break after our tries expire
try:
return method(*args, **kwargs)
except RateLimitException as e:
if tries <= 1:
raise
period = float(e.period)
self.log.warn('rate limit encountered, pausing '
'for %ds and trying again, %d remaining',
period, tries)
sleep(period)
tries -= 1
raise
def zones_retrieve(self, name):
return self._try(self._zones.retrieve, name)