Skip to content

Commit

Permalink
Merge branch 'main' of github.com:wakamex/ape-alchemy
Browse files Browse the repository at this point in the history
  • Loading branch information
wakamex committed Nov 7, 2022
2 parents 7b42b54 + a952577 commit ef1f527
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions ape_alchemy/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 = (
Expand Down

0 comments on commit ef1f527

Please sign in to comment.