diff --git a/ape_alchemy/provider.py b/ape_alchemy/provider.py index e585f1b..f01cdc4 100644 --- a/ape_alchemy/provider.py +++ b/ape_alchemy/provider.py @@ -136,12 +136,11 @@ def get_virtual_machine_error(self, exception: Exception) -> VirtualMachineError return VirtualMachineError(message=message) def _make_request(self, endpoint: str, parameters: list) -> Any: - mint_retry_delay = 1000 + min_retry_delay = 1000 retry_backoff_factor = 2 max_retry_delay = 30000 max_retries = 3 - # RETRY_INTERVAL = 1000 - RETRY_JITTER = 250 + retry_jitter = 250 for i in range(0,max_retries): print(f"_make_request attempt {i}") try: @@ -157,10 +156,10 @@ def _make_request(self, endpoint: str, parameters: list) -> Any: if isinstance(error_data, dict) else error_data ) - if message.__contains__("exceeded its compute units"): - RETRY_INTERVAL = min(max_retry_delay, mint_retry_delay * retry_backoff_factor ** i) - print(f"Alchemy compute units exceeded, retrying #{i} in {RETRY_INTERVAL} ms") - delay = RETRY_INTERVAL + random.randint(0, RETRY_JITTER) + if "exceeded its compute units" in message: + retry_interval = min(max_retry_delay, min_retry_delay * retry_backoff_factor ** i) + print(f"Alchemy compute units exceeded, retrying #{i} in {retry_interval} ms") + delay = retry_interval + random.randint(0, retry_jitter) time.sleep(delay / 1000) continue cls = (