api: Fix unused long-polling retry parameter.

This parameter was intended to control whether we give a long timeout
and related behavior, but it was accidentally not being passed into
the second layer of the library from the first.

While we're fixing it, make it actually limit the length of a timeout
to something reasonable.
This commit is contained in:
derAnfaenger 2017-10-06 17:00:41 +02:00 committed by Tim Abbott
parent 1e8e1f17c4
commit a7bfe692fa

View file

@ -434,6 +434,15 @@ class Client(object):
if files is None: if files is None:
files = [] files = []
if longpolling:
# When long-polling, set timeout to 90 sec as a balance
# between a low traffic rate and a still reasonable latency
# time in case of a connection failure.
request_timeout = 90
else:
# Otherwise, 15s should be plenty of time.
request_timeout = 15
request = {} request = {}
req_files = [] req_files = []
@ -491,10 +500,11 @@ class Client(object):
if files: if files:
kwargs['files'] = req_files kwargs['files'] = req_files
# Actually make the request!
res = self.session.request( res = self.session.request(
method, method,
urllib.parse.urljoin(self.base_url, url), urllib.parse.urljoin(self.base_url, url),
timeout=90, timeout=request_timeout,
**kwargs) **kwargs)
# On 50x errors, try again after a short sleep # On 50x errors, try again after a short sleep
@ -547,7 +557,8 @@ class Client(object):
# type: (str, str, Dict[str, Any], bool, List[IO]) -> Dict[str, Any] # type: (str, str, Dict[str, Any], bool, List[IO]) -> Dict[str, Any]
if request is None: if request is None:
request = dict() request = dict()
return self.do_api_query(request, API_VERSTRING + url, method=method, files=files) return self.do_api_query(request, API_VERSTRING + url, method=method,
longpolling=longpolling, files=files)
def call_on_each_event(self, callback, event_types=None, narrow=None): def call_on_each_event(self, callback, event_types=None, narrow=None):
# type: (Callable, Optional[List[str]], Any) -> None # type: (Callable, Optional[List[str]], Any) -> None