Skip to content

Commit 88aa879

Browse files
authored
Merge pull request #315 from ynput/enhancement/retry_on_502_or_502_status_code
Allow to retry on server response with status code 502 or 503
2 parents d4ab2ee + 7dda6d7 commit 88aa879

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

ayon_api/server_api.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,20 @@ def _do_rest_request(self, function, url, **kwargs):
12281228
for retry_idx in reversed(range(max_retries)):
12291229
try:
12301230
response = function(url, **kwargs)
1231+
1232+
# Usually these mean, try later.
1233+
# 502: returned by the proxy: nginx
1234+
# 503: returned by the server: if no capacity
1235+
if response.status_code in {502, 503}:
1236+
new_response = RestApiResponse(response)
1237+
self.log.warning(
1238+
"Server returned %s status code."
1239+
" Retrying with longer delay...",
1240+
response.status_code
1241+
)
1242+
if retry_idx != 0:
1243+
time.sleep(2)
1244+
continue
12311245
break
12321246

12331247
except ConnectionRefusedError:
@@ -1269,7 +1283,8 @@ def _do_rest_request(self, function, url, **kwargs):
12691283
}
12701284
)
12711285

1272-
time.sleep(0.1)
1286+
if retry_idx != 0:
1287+
time.sleep(0.1)
12731288

12741289
if new_response is not None:
12751290
return new_response

0 commit comments

Comments
 (0)