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):
|
||||
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)
|
||||
|
Reference in New Issue
Block a user