Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
after=after_log(logger, logging.WARN),
)
def init():
try:
# Try to create session to check if DB is awake
db_session.execute("SELECT 1")
except Exception as e:
logger.error(e)
raise e
@retry(
stop=stop_after_attempt(max_tries),
wait=wait_fixed(wait_seconds),
before=before_log(logger, logging.INFO),
after=after_log(logger, logging.WARN),
)
def init():
try:
# Try to create session to check if DB is awake
db_session.execute("SELECT 1")
except Exception as e:
logger.error(e)
raise e
after=tenacity.after_log(LOG, logging.DEBUG),
# Reraise exceptions if our final attempt fails.
reraise=True,
# Retry on certain failures.
retry=(tenacity.retry_if_exception_type(BaseRetryable)),
# Stop after the configured timeout.
stop=tenacity.stop_after_delay(
int(self.ngs_config['ngs_commit_timeout'])),
# Wait for the configured interval between attempts.
wait=tenacity.wait_fixed(
int(self.ngs_config['ngs_commit_interval'])),
)
def commit():
try:
net_connect.commit()
except ValueError as e:
# Netmiko raises ValueError on commit failure, and appends the
after=tenacity.after_log(logger, logging.INFO))
def _write_csv_to_s3_retrying(fs: Any, path: str, buffer: bytes) -> None:
with fs.open(path, "wb") as f:
f.write(buffer)
def decorator(fun: Callable):
default_kwargs = {
'wait': tenacity.wait_exponential(multiplier=1, max=100),
'retry': retry_if_temporary_quota(),
'before': tenacity.before_log(logger, logging.DEBUG),
'after': tenacity.after_log(logger, logging.DEBUG),
}
default_kwargs.update(**kwargs)
return tenacity.retry(
*args, **default_kwargs
)(fun)
return decorator
def _retry_send(self, function: Callable, attempt=10, *args, **kwargs):
retry_configuration = tenacity.Retrying(
stop=tenacity.stop_after_attempt(attempt),
wait=tenacity.wait_fixed(3) + tenacity.wait_random(0, 2),
after=tenacity.after_log(logger, logger.level) if logger else None,
reraise=True,
)
return retry_configuration(function, *args, **kwargs)
def retry_api_call(func, config, logger=None,
*args, **kwargs):
retry = tenacity.Retrying(
retry=retry_if_exception(
lambda e: getattr(e, 'response', {}).get(
'Error', {}).get('Code', None) in config.exceptions
if e else False),
stop=stop_after_attempt(config.attempt),
wait=wait_exponential(multiplier=config.multiplier,
max=config.max_delay,
exp_base=config.exponential_base),
after=after_log(logger, logger.level) if logger else None,
reraise=True
)
return retry(func, *args, **kwargs)