Skip to content

Commit 407ab14

Browse files
authored
Merge pull request #155 from jkeyes/dev
3.0.5 Increasing default request timeout.
2 parents 37d8c97 + d7edd39 commit 407ab14

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Changelog
22
=========
3+
* 3.0.5
4+
* Increased default request timeout to 90 seconds. This can also be set by the `INTERCOM_REQUEST_TIMEOUT` environment variable. (`#154 <https://github.com/jkeyes/python-intercom/pull/154>`_)
35
* 3.0.4
46
* Added `resource_type` attribute to lightweight classes. (`#153 <https://github.com/jkeyes/python-intercom/pull/153>`_)
57
* 3.0.3

intercom/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
MultipleMatchingUsersError, RateLimitExceeded, ResourceNotFound,
77
ServerError, ServiceUnavailableError, UnexpectedError, TokenUnauthorizedError)
88

9-
__version__ = '3.0.4'
9+
__version__ = '3.0.5'
1010

1111

1212
RELATED_DOCS_TEXT = "See https://github.com/jkeyes/python-intercom \

intercom/request.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,31 @@
77
import certifi
88
import json
99
import logging
10+
import os
1011
import requests
1112

1213
logger = logging.getLogger('intercom.request')
1314

1415

16+
def configure_timeout():
17+
"""Configure the request timeout."""
18+
timeout = os.getenv('INTERCOM_REQUEST_TIMEOUT', '90')
19+
try:
20+
return int(timeout)
21+
except ValueError:
22+
logger.warning('%s is not a valid timeout value.', timeout)
23+
return 90
24+
25+
1526
class Request(object):
1627

17-
timeout = 10
28+
timeout = configure_timeout()
1829

1930
def __init__(self, http_method, path, http_session=None):
2031
self.http_method = http_method
2132
self.path = path
2233
self.http_session = http_session
2334

24-
2535
def execute(self, base_url, auth, params):
2636
return self.send_request_to_path(base_url, auth, params)
2737

tests/unit/test_request.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,25 @@ def it_needs_encoding_or_apparent_encoding(self):
332332
@istest
333333
def it_allows_the_timeout_to_be_changed(self):
334334
from intercom.request import Request
335-
eq_(10, Request.timeout)
336-
Request.timeout = 3
337-
eq_(3, Request.timeout)
335+
try:
336+
eq_(90, Request.timeout)
337+
Request.timeout = 3
338+
eq_(3, Request.timeout)
339+
finally:
340+
Request.timeout = 90
341+
342+
@istest
343+
def it_allows_the_timeout_to_be_configured(self):
344+
import os
345+
from intercom.request import configure_timeout
346+
347+
# check the default
348+
eq_(90, configure_timeout())
349+
350+
# override the default
351+
os.environ['INTERCOM_REQUEST_TIMEOUT'] = '20'
352+
eq_(20, configure_timeout())
353+
354+
# ignore bad timeouts, reset to default 90
355+
os.environ['INTERCOM_REQUEST_TIMEOUT'] = 'abc'
356+
eq_(90, configure_timeout())

0 commit comments

Comments
 (0)