misc: add a REQUESTS_TIMEOUT settings for requests calls (#20825)
This commit is contained in:
parent
0218258a15
commit
a698bcdd0d
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue