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