misc: add a REQUESTS_TIMEOUT settings for requests calls (#20825)

This commit is contained in:
Thomas NOËL 2017-12-20 15:00:26 +01:00
parent 0218258a15
commit a698bcdd0d
3 changed files with 8 additions and 8 deletions

View File

@ -292,6 +292,8 @@ def _http_request(url, method='GET', body=None, headers={}, cert_file=None, time
password = ''
auth = (username, password)
timeout = timeout or settings.REQUESTS_TIMEOUT
try:
response = requests.request(method, url, headers=headers, data=body,
timeout=timeout, cert=cert_file, proxies=settings.REQUESTS_PROXIES)

View File

@ -151,6 +151,10 @@ WCS_LEGACY_CONFIG_FILE = None
# http://docs.python-requests.org/en/master/user/advanced/?highlight=proxy#proxies
REQUESTS_PROXIES = None
# timeout used in python-requests call, in seconds
# we use 28s by default: timeout just before web server, which is usually 30s
REQUESTS_TIMEOUT = 28
local_settings_file = os.environ.get('WCS_SETTINGS_FILE',
os.path.join(os.path.dirname(__file__), 'local_settings.py'))
if os.path.exists(local_settings_file):

View File

@ -34,8 +34,6 @@ from qommon.template import Template
from wcs.api_utils import sign_url, get_secret_and_orig, MissingSecret
from wcs.workflows import WorkflowStatusItem
TIMEOUT = 30
def call_webservice(url, qs_data=None, request_signature_key=None,
method=None, post_data=None, post_formdata=None, formdata=None,
**kwargs):
@ -99,19 +97,15 @@ def call_webservice(url, qs_data=None, request_signature_key=None,
payload = formdata_dict
if method == 'POST':
timeout = TIMEOUT
if payload:
headers['Content-type'] = 'application/json'
payload = json.dumps(payload, cls=JSONEncoder,
encoding=get_publisher().site_charset)
# increase timeout for huge loads, one second every 65536
# bytes, to match a country 512kbps DSL line.
timeout += len(payload) / 65536
response, status, data, auth_header = qommon.misc.http_post_request(
url, payload, headers=headers, timeout=timeout)
url, payload, headers=headers)
else:
response, status, data, auth_header = qommon.misc.http_get_page(
url, headers=headers, timeout=TIMEOUT)
url, headers=headers)
return (response, status, data)