Skip to content

Commit

Permalink
lower case local constants
Browse files Browse the repository at this point in the history
  • Loading branch information
wakamex committed Nov 7, 2022
1 parent 61ab88d commit 7b42b54
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions ape_alchemy/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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.")

0 comments on commit 7b42b54

Please sign in to comment.