diff --git a/ape_alchemy/provider.py b/ape_alchemy/provider.py index 40f1d6b..4b49c55 100644 --- a/ape_alchemy/provider.py +++ b/ape_alchemy/provider.py @@ -139,8 +139,16 @@ def get_virtual_machine_error(self, exception: Exception) -> VirtualMachineError return VirtualMachineError(message=message) - def _make_request(self, endpoint: str, parameters: list,min_retry_delay:int = 1000, retry_backoff_factor:int = 2, - max_retry_delay:int = 30000, max_retries:int = 3, retry_jitter:int = 250) -> Any: + def _make_request( + self, + endpoint: str, + parameters: list, + min_retry_delay: int=1_000, # 1 second + retry_backoff_factor: int=2, # exponential backoff + max_retry_delay: int=30_000, # 30 seconds + max_retries: int=3, + retry_jitter: int=250, + ) -> Any: for i in range(0,max_retries): try: @@ -157,8 +165,12 @@ def _make_request(self, endpoint: str, parameters: list,min_retry_delay:int = 10 else error_data ) if "exceeded its compute units" in message: - retry_interval = min(max_retry_delay, min_retry_delay * retry_backoff_factor ** i) - logger.info(f"Alchemy compute units exceeded, retrying #{i} in {retry_interval} ms") + retry_interval = min( + max_retry_delay, + min_retry_delay * retry_backoff_factor ** i + ) + logger.info(f"Alchemy compute units exceeded, retrying," + + f" attempt #{i+1}/{max_retries} in {retry_interval} ms") delay = retry_interval + random.randint(0, retry_jitter) time.sleep(delay / 1000) continue