Reduce retrier message repetition

by combining messages, we can provide the same information in fewer log messages
This commit is contained in:
Matthias 2021-12-27 16:47:34 +01:00
parent 54858a0bbb
commit ef2b326262

View File

@ -80,9 +80,9 @@ def retrier_async(f):
try: try:
return await f(*args, **kwargs) return await f(*args, **kwargs)
except TemporaryError as ex: except TemporaryError as ex:
logger.warning('%s() returned exception: "%s"', f.__name__, ex) msg = f'{f.__name__}() returned exception: "{ex}". '
if count > 0: if count > 0:
logger.warning('retrying %s() still for %s times', f.__name__, count) logger.warning(msg + f'Retrying still for {count} times.')
count -= 1 count -= 1
kwargs['count'] = count kwargs['count'] = count
if isinstance(ex, DDosProtection): if isinstance(ex, DDosProtection):
@ -98,7 +98,7 @@ def retrier_async(f):
await asyncio.sleep(backoff_delay) await asyncio.sleep(backoff_delay)
return await wrapper(*args, **kwargs) return await wrapper(*args, **kwargs)
else: else:
logger.warning('Giving up retrying: %s()', f.__name__) logger.warning(msg + 'Giving up.')
raise ex raise ex
return wrapper return wrapper
@ -111,9 +111,9 @@ def retrier(_func=None, retries=API_RETRY_COUNT):
try: try:
return f(*args, **kwargs) return f(*args, **kwargs)
except (TemporaryError, RetryableOrderError) as ex: except (TemporaryError, RetryableOrderError) as ex:
logger.warning('%s() returned exception: "%s"', f.__name__, ex) msg = f'{f.__name__}() returned exception: "{ex}". '
if count > 0: if count > 0:
logger.warning('retrying %s() still for %s times', f.__name__, count) logger.warning(msg + f'Retrying still for {count} times.')
count -= 1 count -= 1
kwargs.update({'count': count}) kwargs.update({'count': count})
if isinstance(ex, (DDosProtection, RetryableOrderError)): if isinstance(ex, (DDosProtection, RetryableOrderError)):
@ -123,7 +123,7 @@ def retrier(_func=None, retries=API_RETRY_COUNT):
time.sleep(backoff_delay) time.sleep(backoff_delay)
return wrapper(*args, **kwargs) return wrapper(*args, **kwargs)
else: else:
logger.warning('Giving up retrying: %s()', f.__name__) logger.warning(msg + 'Giving up.')
raise ex raise ex
return wrapper return wrapper
# Support both @retrier and @retrier(retries=2) syntax # Support both @retrier and @retrier(retries=2) syntax