diff --git a/ape_alchemy/provider.py b/ape_alchemy/provider.py index a856d39..e585f1b 100644 --- a/ape_alchemy/provider.py +++ b/ape_alchemy/provider.py @@ -136,13 +136,13 @@ def get_virtual_machine_error(self, exception: Exception) -> VirtualMachineError return VirtualMachineError(message=message) def _make_request(self, endpoint: str, parameters: list) -> Any: - MIN_RETRY_DELAY = 1000 - RETRY_BACKOFF_FACTOR = 2 - MAX_RETRY_DELAY = 30000 - MAX_RETRIES = 3 + mint_retry_delay = 1000 + retry_backoff_factor = 2 + max_retry_delay = 30000 + max_retries = 3 # RETRY_INTERVAL = 1000 RETRY_JITTER = 250 - for i in range(0,MAX_RETRIES): + for i in range(0,max_retries): print(f"_make_request attempt {i}") try: return super()._make_request(endpoint, parameters) @@ -158,7 +158,7 @@ def _make_request(self, endpoint: str, parameters: list) -> Any: else error_data ) if message.__contains__("exceeded its compute units"): - RETRY_INTERVAL = min(MAX_RETRY_DELAY, MIN_RETRY_DELAY * RETRY_BACKOFF_FACTOR ** i) + 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) time.sleep(delay / 1000) @@ -169,4 +169,4 @@ def _make_request(self, endpoint: str, parameters: list) -> Any: else AlchemyProviderError ) raise cls(message) from err - raise AlchemyProviderError(f"Rate limited for ${MAX_RETRIES} consecutive attempts.") + raise AlchemyProviderError(f"Rate limited for ${max_retries} consecutive attempts.")