Skip to content
Snippets Groups Projects
Commit 990cc4ecf4bd authored by Houzefa Abbasbhay's avatar Houzefa Abbasbhay :slight_smile:
Browse files

Configurable timeout, default is 20 seconds

parent 834be989e557
No related branches found
No related tags found
1 merge request!12Topic/11.0/zouzou
...@@ -2,6 +2,11 @@ ...@@ -2,6 +2,11 @@
NEWS NEWS
==== ====
11.0.2.5.0
==========
* Configurable timeout for redner calls, default is 20 seconds.
11.0.2.4.1 11.0.2.4.1
========== ==========
......
...@@ -18,4 +18,5 @@ ...@@ -18,4 +18,5 @@
redner.server_url = http://dockerhost:7000 redner.server_url = http://dockerhost:7000
redner.api_key = <your API key here> redner.api_key = <your API key here>
redner.account = <your account name> redner.account = <your account name>
redner.timeout = 20
...@@ -21,4 +22,5 @@ ...@@ -21,4 +22,5 @@
``redner.timeout`` is in seconds; defaults to 20 seconds per redner call.
**Pro tip**: You can use mjml-app_ to prototype your email templates. **Pro tip**: You can use mjml-app_ to prototype your email templates.
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
"name": "Redner", "name": "Redner",
"summary": """ "summary": """
Allows to generate transactional emails and documents in PDF or HTML format""", Allows to generate transactional emails and documents in PDF or HTML format""",
"version": "11.0.2.4.1", "version": "11.0.2.5.0",
"author": "XCG Consulting", "author": "XCG Consulting",
"category": "Technical", "category": "Technical",
"depends": ["base", "mail", "converter"], "depends": ["base", "mail", "converter"],
......
...@@ -15,9 +15,9 @@ ...@@ -15,9 +15,9 @@
class Redner(object): class Redner(object):
def __init__(self, api_key, server_url, account): def __init__(self, api_key, server_url, account, timeout):
"""Initialize the API client """Initialize the API client
Args: Args:
api_key(str): provide your Redner API key. api_key(str): provide your Redner API key.
server_url(str): Redner server URL. server_url(str): Redner server URL.
...@@ -19,7 +19,8 @@ ...@@ -19,7 +19,8 @@
"""Initialize the API client """Initialize the API client
Args: Args:
api_key(str): provide your Redner API key. api_key(str): provide your Redner API key.
server_url(str): Redner server URL. server_url(str): Redner server URL.
timeout(float): Timeout per Redner call, in seconds.
""" """
...@@ -24,4 +25,5 @@ ...@@ -24,4 +25,5 @@
""" """
self.session = requests.session() self.api_key = api_key
self.server_url = server_url
self.account = account self.account = account
...@@ -27,6 +29,7 @@ ...@@ -27,6 +29,7 @@
self.account = account self.account = account
self.server_url = server_url self.timeout = timeout
self.api_key = api_key
self.session = requests.sessions.Session()
self.templates = Templates(self) self.templates = Templates(self)
def call(self, path, http_verb="post", **params): def call(self, path, http_verb="post", **params):
...@@ -70,7 +73,10 @@ ...@@ -70,7 +73,10 @@
start = time.time() start = time.time()
r = getattr(self.session, http_verb, "post")( r = getattr(self.session, http_verb, "post")(
url, json=params, headers={"Rednerd-API-Key": self.api_key} url,
json=params,
headers={"Rednerd-API-Key": self.api_key},
timeout=self.timeout,
) )
complete_time = time.time() - start complete_time = time.time() - start
...@@ -96,7 +102,7 @@ ...@@ -96,7 +102,7 @@
def ping(self): def ping(self):
"""Try to establish a connection to server""" """Try to establish a connection to server"""
conn = self.session.get(self.server_url) conn = self.session.get(self.server_url, timeout=self.timeout)
if conn.status_code != requests.codes.ok: if conn.status_code != requests.codes.ok:
raise ValidationError("Cannot Establish a connection to server") raise ValidationError("Cannot Establish a connection to server")
return conn return conn
......
...@@ -86,6 +86,7 @@ ...@@ -86,6 +86,7 @@
config_model.get_param("redner.api_key"), config_model.get_param("redner.api_key"),
config_model.get_param("redner.server_url"), config_model.get_param("redner.server_url"),
config_model.get_param("redner.account"), config_model.get_param("redner.account"),
int(config_model.get_param("redner.timeout", default="20")),
) )
return self._redner return self._redner
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment