Skip to content

Commit

Permalink
Add Exponential Backoff to Model Export Status Check (#238)
Browse files Browse the repository at this point in the history
Co-authored-by: UltralyticsAssistant <[email protected]>
  • Loading branch information
yogendrasinghx and UltralyticsAssistant authored Dec 27, 2024
1 parent e7fd8dd commit a7a1998
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions tests/features/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,24 @@ def is_model_exported(model_id, format_name):
payload = json.dumps({"modelId": model_id, "format": format_name})
headers = {"x-api-key": TestData().get_auth_data()["valid_api_key"], "Content-Type": "application/json"}

start_time = time.time()
timeout = 60
backoff_times = [60, 120, 240, 480] # Exponential backoff waits in seconds

while time.time() - start_time < timeout:
response = requests.post(url=url, headers=headers, data=payload)
data = response.json()
for wait_time in backoff_times:
try:
response = requests.post(url=url, headers=headers, data=payload)
data = response.json()

if data.get("message") == "Export ready!":
return True
if data.get("message") == "Export ready!":
return True

time.sleep(10)
print(f"Export not ready. Retrying in {wait_time} seconds...")
time.sleep(wait_time)

except Exception as e:
print(f"Error during export check: {e}")

if wait_time == backoff_times[-1]:
print("Max retries reached. Export not ready.")

return False

Expand Down

0 comments on commit a7a1998

Please sign in to comment.