Skip to content

Commit

Permalink
even better autoretry code
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Sep 15, 2024
1 parent 9e1921d commit f693b1a
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion action.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,18 @@ def send_payload_to_api(args, output_files_gcs_paths, logs_gcs_path, workflow_na

# Send POST request
headers = {"Content-Type": "application/json"}
response = requests.post(args.api_endpoint, headers=headers, data=payload_json, timeout=REQUEST_TIMEOUT)
response = None
try:
response = requests.post(args.api_endpoint, headers=headers, data=payload_json, timeout=REQUEST_TIMEOUT)
except Exception as e:
if can_retry:
print(f"API request failed with exception {e}, retrying in 10 seconds")
time.sleep(10)
send_payload_to_api(args, output_files_gcs_paths, logs_gcs_path, workflow_name, start_time, end_time, vram_time_series, status, False)
return
print(f"API request failed with exception {e}")
traceback.print_exc()
raise e
try:
print("#### Payload ####")
pprint.pprint(payload)
Expand All @@ -211,6 +222,7 @@ def send_payload_to_api(args, output_files_gcs_paths, logs_gcs_path, workflow_na
# Check the response code
if response.status_code != 200:
if can_retry:
print(f"API request failed with status code {response.status_code} and text {response.text}, retrying in 10 seconds")
time.sleep(10)
send_payload_to_api(args, output_files_gcs_paths, logs_gcs_path, workflow_name, start_time, end_time, vram_time_series, status, False)
return
Expand Down

0 comments on commit f693b1a

Please sign in to comment.