def retry_pattern(backoff_type, exception, **wait_gen_kwargs):
def log_retry_attempt(details):
_, exception, _ = sys.exc_info()
LOGGER.info(exception)
LOGGER.info('Caught retryable error after %s tries. Waiting %s more seconds then retrying...',
details["tries"],
details["wait"])
def should_retry_api_error(exception):
if isinstance(exception, FacebookRequestError):
return exception.api_transient_error()
elif isinstance(exception, InsightsJobTimeout):
return True
return False
return backoff.on_exception(
backoff_type,
exception,
jitter=None,
on_backoff=log_retry_attempt,
giveup=lambda exc: not should_retry_api_error(exc),
**wait_gen_kwargs
)
评论列表
文章目录