Skip to content

Commit

Permalink
Add timeout to RenderServer.render()
Browse files Browse the repository at this point in the history
This commit adds a configurable timeout to the `render` method signature
within `RenderServer`. This defaults to 10 seconds; 5 for sending the
request and 5 for reading the response.
  • Loading branch information
cburmeister committed Feb 23, 2017
1 parent be10f22 commit 44186cb
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions react/render_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ def __unicode__(self):


class RenderServer(object):
def render(self, path, props=None, to_static_markup=False, request_headers=None):
def render(
self, path, props=None, to_static_markup=False, request_headers=None,
timeout=None
):
url = conf.settings.RENDER_URL

if props is not None:
Expand All @@ -45,12 +48,17 @@ def render(self, path, props=None, to_static_markup=False, request_headers=None)
if request_headers is not None:
all_request_headers.update(request_headers)

# Add a send/receive timeout with the request if not specified
if not isinstance(timeout, (tuple, int, float)):
timeout = (5, 5)

try:
res = requests.post(
url,
data=serialized_options,
headers=all_request_headers,
params={'hash': options_hash}
params={'hash': options_hash},
timeout=timeout
)
except requests.ConnectionError:
raise RenderServerError('Could not connect to render server at {}'.format(url))
Expand Down

0 comments on commit 44186cb

Please sign in to comment.