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