Skip to content

Commit bbe8954

Browse files
False 500 testing (#57)
* push wip code for handling false 500s * query task response via uuid * cleaning up, remove print statements * raise 409 error when retry history is empty * small changes - we don't need to force a retry on a 409, it will only result in another 409, so let's just directly handle the issue - try_history back to 500 * Update api.py * more formatting * Update api.py * fomatting Co-authored-by: Kevin Xu <kevin.xu@scale.com>
1 parent b7ffab5 commit bbe8954

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

scaleapi/api.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,28 @@ def _api_request(
109109
json = None
110110
if res.status_code == 200:
111111
json = res.json()
112+
elif res.status_code == 409 and "task" in endpoint and body.get("unique_id"):
113+
retry_history = res.raw.retries.history
114+
# Example RequestHistory tuple
115+
# RequestHistory(method='POST',
116+
# url='/v1/task/imageannotation',
117+
# error=None,
118+
# status=409,
119+
# redirect_location=None)
120+
if retry_history != ():
121+
# See if the first retry was a 500 error
122+
if retry_history[0][3] == 500:
123+
uuid = body["unique_id"]
124+
newUrl = f"{self.base_api_url}/tasks?unique_id={uuid}"
125+
# grab task from api
126+
newRes = self._http_request(
127+
"GET", newUrl, headers=headers, auth=auth
128+
)
129+
json = newRes.json()["docs"][0]
130+
else:
131+
self._raise_on_respose(res)
112132
else:
113133
self._raise_on_respose(res)
114-
115134
return json
116135

117136
def get_request(self, endpoint, params=None):

0 commit comments

Comments
 (0)