Skip to content
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
11 changes: 7 additions & 4 deletions hca/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def special_cli_command(self, required_argument, optional_argument=""):
import requests
from requests.adapters import HTTPAdapter
from requests_oauthlib import OAuth2Session
from urllib3.util import retry
from urllib3.util import retry, timeout

from .. import get_config, logger
from .compat import USING_PYTHON2
Expand All @@ -107,6 +107,9 @@ def __init__(self, retry_after_status_codes={301}, **kwargs):


class _ClientMethodFactory(object):
retry_policy = RetryPolicy(read=10, status=10, status_forcelist=frozenset({500, 502, 503, 504}))
timeout_policy = timeout.Timeout(connect=60, read=120)

def __init__(self, client, parameters, path_parameters, http_method, method_name, method_data, body_props):
self.__dict__.update(locals())
self._context_manager_response = None
Expand All @@ -124,15 +127,15 @@ def _request(self, req_args, url=None, stream=False, headers=None):
session = self.client.get_authenticated_session()
else:
session = self.client.get_session()
retry_policy = RetryPolicy(read=10, status=10, status_forcelist=frozenset({502, 503, 504}))
adapter = HTTPAdapter(max_retries=retry_policy)
adapter = HTTPAdapter(max_retries=self.retry_policy)
session.mount('http://', adapter)
session.mount('https://', adapter)

# TODO: (akislyuk) if using service account credentials, use manual refresh here
json_input = body if self.body_props else None
headers = headers if headers else {}
res = session.request(self.http_method, url, params=query, json=json_input, stream=stream, headers=headers)
res = session.request(self.http_method, url, params=query, json=json_input, stream=stream, headers=headers,
timeout=self.timeout_policy)
if res.status_code >= 400:
raise SwaggerAPIException(response=res)
return res
Expand Down