Add exponentional backoff for ometa REST Client (#711)

Co-authored-by: Mithun Mathew <matt@Mithuns-MacBook-Pro.local>
This commit is contained in:
Matt 2021-10-11 11:20:36 -07:00 committed by GitHub
parent 79ca909f2f
commit 78e97c81ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -124,23 +124,21 @@ class REST(object):
else:
opts['data'] = data
retry = self._retry
if retry < 0:
retry = 0
total_retries = self._retry if self._retry > 0 else 0
retry = total_retries
while retry >= 0:
try:
logger.debug('URL {}, method {}'.format(url, method))
logger.debug('Data {}'.format(opts))
return self._one_request(method, url, opts, retry)
except RetryException:
retry_wait = self._retry_wait
retry_wait = self._retry_wait * (total_retries - retry + 1)
logger.warning(
'sleep {} seconds and retrying {} '
'{} more time(s)...'.format(
retry_wait, url, retry))
time.sleep(retry_wait)
retry -= 1
continue
def _one_request(self, method: str, url: URL, opts: dict, retry: int):
"""