Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new:dev:SDK-386_improvement: Changing retry conditions for 503 response #311

Merged
merged 14 commits into from
Mar 23, 2020
18 changes: 14 additions & 4 deletions qds_sdk/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,15 @@ def _handle_error(response):
elif code == 422:
sys.stderr.write(response.text + "\n")
raise ResourceInvalid(response)
elif code in (502, 503, 504):
elif code in (502, 504):
sys.stderr.write(response.text + "\n")
raise RetryWithDelay(response)
elif code == 449:
sys.stderr.write(response.text + "\n")
raise RetryWithDelay(response, "Data requested is unavailable. Retrying...")
elif code == 429:
raise RetryWithDelay(response, Connection.get_error_message(code))
elif code in (429, 503):
sys.stderr.write(response.text + "\n")
raise ApiThrottledRetry(response, "Too many requests. Retrying...")
raise ApiThrottledRetry(response, Connection.get_error_message(code))
elif 401 <= code < 500:
sys.stderr.write(response.text + "\n")
raise ClientError(response)
Expand All @@ -214,3 +214,13 @@ def _validate_json(response):
except Exception as e:
sys.stderr.write("Error: {0}\nInvalid Response from Server, please contact Qubole Support".format(str(e)))
raise ServerError(response)

def get_error_message(code):
if code == 429:
return "Too many requests. Retrying..."
elif code == 449:
return "Data requested is unavailable. Retrying..."
elif code == 503:
return "Service Unavailable. Retrying..."
else:
return ''
3 changes: 2 additions & 1 deletion qds_sdk/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class MethodNotAllowed(ClientError):


class ApiThrottledRetry(ClientError):
"""An error raised when upstream requests are throttled."""
"""An error raised when upstream requests are throttled or Service Unavailable."""
# 429 Too Many Requests
# 503 Service Unavailable
pass