Skip to content

Commit

Permalink
feat: ETH_RETRY_SUPPRESS_LOGS env var (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored Jan 11, 2024
1 parent 7910d6e commit 884215b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions eth_retry/ENVIRONMENT_VARIABLES.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

ETH_RETRY_DISABLED = bool(os.environ.get("ETH_RETRY_DISABLED"))
ETH_RETRY_DEBUG = bool(os.environ.get("ETH_RETRY_DEBUG"))
MIN_SLEEP_TIME = int(os.environ.get("MIN_SLEEP_TIME", 10))
MAX_SLEEP_TIME = int(os.environ.get("MAX_SLEEP_TIME", 20))
# NOTE: this will suppress logs up to `ETH_RETRY_SUPPRESS_LOGS` times, then they will log as usual
ETH_RETRY_SUPPRESS_LOGS = int(os.environ.get("ETH_RETRY_SUPPRESS_LOGS", -1))
MIN_SLEEP_TIME = int(os.environ.get("MIN_SLEEP_TIME", 5))
MAX_SLEEP_TIME = int(os.environ.get("MAX_SLEEP_TIME", 15))
MAX_RETRIES = int(os.environ.get("MAX_RETRIES", 10))
6 changes: 4 additions & 2 deletions eth_retry/eth_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def auto_retry_wrap(*args: P.args, **kwargs: P.kwargs) -> T:
except Exception as e:
if not should_retry(e, failures):
raise
logger.warning(f'{str(e)} [{failures}]')
if failures > ENVS.ETH_RETRY_SUPPRESS_LOGS:
logger.warning(f'{str(e)} [{failures}]')
if ENVS.ETH_RETRY_DEBUG:
logger.exception(e)

Expand All @@ -89,7 +90,8 @@ async def auto_retry_wrap_async(*args: P.args, **kwargs: P.kwargs) -> T:
except Exception as e:
if not should_retry(e, failures):
raise
logger.warning(f'{str(e)} [{failures}]')
if failures > ENVS.ETH_RETRY_SUPPRESS_LOGS:
logger.warning(f'{str(e)} [{failures}]')
if ENVS.ETH_RETRY_DEBUG:
logger.exception(e)

Expand Down

0 comments on commit 884215b

Please sign in to comment.