Skip to content

Commit 8395079

Browse files
authored
Configurable timeout (#32)
Allow the 10 second timeout to be configured
1 parent 258faa2 commit 8395079

File tree

5 files changed

+36
-6
lines changed

5 files changed

+36
-6
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
Changelog
22
=========
33

4+
### 1.3.2
5+
6+
Python package bumped to 1.3.2:
7+
- Add a configurable timeout using the setting `REACT_TIMEOUT`
8+
9+
*Note:* Python only release. JavaScript package remains at 1.3.1
10+
411
### 1.3.1
512

613
Python package bumped to 1.3.1:

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ Arguments:
7676
`renderToString` method to be used.
7777
- `json_encoder` *optional* — a class which is used to encode the JSON which is sent to the
7878
renderer. Defaults to `django.core.serializers.json.DjangoJSONEncoder`.
79+
- `timeout` *optional* - override the service timeout.
7980

8081

8182
RenderedComponent
@@ -115,6 +116,20 @@ react-service settings
115116
By default, the service will attempt to load any arbitrary path it is given.
116117
Can also be set via the `REACT_WHITELIST` environment variable.
117118

119+
Django settings
120+
----------------
121+
122+
- `REACT_SERVICE_URL`
123+
- Customer URL for the render service (eg. for changing port)
124+
- Default: `http://localhost:63578/render`
125+
- `REACT_FAIL_SAFE`
126+
- If there is a problem with the service, do not raise an exception, and return empty HTML
127+
(allowing the client-side JS to take over)
128+
- Default: `False`
129+
- `REACT_TIMEOUT`
130+
- How long (in seconds) should it wait for nodejs to render the component
131+
- Default: `10`
132+
118133

119134
Running the tests
120135
-----------------

react_render/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
DEFAULT_SERVICE_URL = 'http://localhost:63578/render'
77

88

9-
def render_component(path_to_source, props=None, to_static_markup=False, json_encoder=None, service_url=None):
9+
def render_component(path_to_source, props=None, to_static_markup=False, json_encoder=None, service_url=None, timeout=10):
1010
if not os.path.exists(path_to_source):
1111
raise ComponentSourceFileNotFound(path_to_source)
1212

@@ -17,7 +17,7 @@ def render_component(path_to_source, props=None, to_static_markup=False, json_en
1717
service_url = DEFAULT_SERVICE_URL
1818

1919
response = requests.post(service_url,
20-
timeout=10.0,
20+
timeout=timeout,
2121
headers={'Content-Type': 'application/json'},
2222
data=json_encoder({
2323
'props': props,

react_render/django/render.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
SERVICE_URL = getattr(settings, 'REACT_SERVICE_URL', DEFAULT_SERVICE_URL)
1515
FAIL_SAFE = getattr(settings, 'REACT_FAIL_SAFE', False)
16+
TIMEOUT = getattr(settings, 'REACT_TIMEOUT', 10)
1617

1718
log = logging.getLogger('react-render-client')
1819

@@ -37,7 +38,7 @@ def render_props(self):
3738
return '{}'
3839

3940

40-
def render_component(path_to_source, props=None, to_static_markup=False, json_encoder=None):
41+
def render_component(path_to_source, props=None, to_static_markup=False, json_encoder=None, timeout=TIMEOUT):
4142
if not os.path.isabs(path_to_source):
4243
# If its using the manifest staticfiles storage, to the hashed name.
4344
# eg. js/hello.js -> js/hello.d0bf07ff5f07.js
@@ -60,8 +61,15 @@ def render_component(path_to_source, props=None, to_static_markup=False, json_en
6061
json_encoder = DjangoJSONEncoder().encode
6162

6263
try:
63-
html = render_core(path_to_source, props, to_static_markup, json_encoder, service_url=SERVICE_URL)
64-
except:
64+
html = render_core(
65+
path_to_source,
66+
props,
67+
to_static_markup,
68+
json_encoder,
69+
service_url=SERVICE_URL,
70+
timeout=timeout,
71+
)
72+
except Exception:
6573
if not FAIL_SAFE:
6674
raise
6775
log.exception('Error while rendering %s', path_to_source)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from setuptools import setup, find_packages
22

3-
VERSION = '1.3.1'
3+
VERSION = '1.3.2'
44

55
setup(
66
name='react-render-client',

0 commit comments

Comments
 (0)