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

Retry all Errors in Case of Get Request #309

Merged
merged 1 commit into from
Feb 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions qds_sdk/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
"""


class MyAdapter(HTTPAdapter):
class RequestAdapter(HTTPAdapter):
def __init__(self, *args, **kwargs):
super(MyAdapter, self).__init__(*args, **kwargs)
super(RequestAdapter, self).__init__(*args, **kwargs)

def init_poolmanager(self, connections, maxsize,block=False):
self.poolmanager = PoolManager(num_pools=connections,
Expand All @@ -49,11 +49,11 @@ def __init__(self, auth, rest_url, skip_ssl_cert_check,
self.base_retry_delay = base_retry_delay
if reuse:
self.session = requests.Session()
self.session.mount('https://', MyAdapter())
self.session.mount('https://', RequestAdapter())

# retries for get requests
self.session_with_retries = requests.Session()
self.session_with_retries.mount('https://', MyAdapter(max_retries=3))
self.session_with_retries.mount('https://', RequestAdapter(max_retries=3))

def retry(ExceptionToCheck, tries=5, delay=10, backoff=2):
def deco_retry(f):
Expand All @@ -78,7 +78,7 @@ def f_retry(self, *args, **kwargs):
return f_retry # true decorator
return deco_retry

@retry((RetryWithDelay, requests.Timeout, ServerError, ApiThrottledRetry))
@retry((RetryWithDelay, requests.Timeout, ServerError, ApiThrottledRetry, Error))
def get_raw(self, path, params=None):
return self._api_call_raw("GET", path, params=params)

Expand Down Expand Up @@ -107,7 +107,7 @@ def _api_call_raw(self, req_type, path, data=None, params=None):
else:
x = requests
x_with_retries = requests.Session()
x_with_retries.mount('https://', MyAdapter(max_retries=3))
x_with_retries.mount('https://', RequestAdapter(max_retries=3))

kwargs = {'headers': self._headers, 'auth': self.auth, 'verify': not self.skip_ssl_cert_check}

Expand All @@ -131,12 +131,12 @@ def _api_call_raw(self, req_type, path, data=None, params=None):
else:
raise NotImplemented

self._validate_json(r)
self._handle_error(r)
return r

def _api_call(self, req_type, path, data=None, params=None):
response = self._api_call_raw(req_type, path, data=data, params=params)
self._validate_json(r)
return response.json()

@staticmethod
Expand Down