Skip to content

Commit

Permalink
style changes
Browse files Browse the repository at this point in the history
  • Loading branch information
wakamex committed Nov 27, 2022
1 parent 0c08e6f commit 7b92b2d
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions ape_alchemy/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down

0 comments on commit 7b92b2d

Please sign in to comment.