Skip to content
Snippets Groups Projects
Commit 42c8bbfecee4 authored by Vincent Hatakeyama's avatar Vincent Hatakeyama
Browse files

:sparkles: Redner server an use an unix socket too so also handle it

parent 62eb3b73a373
No related branches found
No related tags found
1 merge request!19forward port of 11.0 features
...@@ -5,6 +5,11 @@ ...@@ -5,6 +5,11 @@
13.0.3.1.0 13.0.3.1.0
========== ==========
(forward port of 11.0.2.6.0)
Redner server an use an unix socket too so also handle it.
(forward port of 11.0.2.5.0) (forward port of 11.0.2.5.0)
* Configurable timeout for redner calls, default is 20 seconds. * Configurable timeout for redner calls, default is 20 seconds.
......
======
Redner Redner
====== ======
......
...@@ -34,5 +34,6 @@ ...@@ -34,5 +34,6 @@
"views/report_redner.xml", "views/report_redner.xml",
"views/menu.xml", "views/menu.xml",
], ],
"external_dependencies": {"python": ["requests_unixsocket"]},
"demo": [], "demo": [],
} }
import logging import logging
import time import time
from urllib.parse import quote
import requests import requests
from odoo import _ from odoo import _
from odoo.exceptions import ValidationError from odoo.exceptions import ValidationError
...@@ -3,14 +4,10 @@ ...@@ -3,14 +4,10 @@
import requests import requests
from odoo import _ from odoo import _
from odoo.exceptions import ValidationError from odoo.exceptions import ValidationError
try: import requests_unixsocket
from urllib.parse import urljoin
except ImportError:
from urlparse import urljoin
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
...@@ -21,8 +18,8 @@ ...@@ -21,8 +18,8 @@
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 or socket path.
timeout(float): Timeout per Redner call, in seconds. timeout(float): Timeout per Redner call, in seconds.
""" """
self.api_key = api_key self.api_key = api_key
...@@ -25,8 +22,7 @@ ...@@ -25,8 +22,7 @@
timeout(float): Timeout per Redner call, in seconds. timeout(float): Timeout per Redner call, in seconds.
""" """
self.api_key = api_key self.api_key = api_key
self.server_url = server_url
self.account = account self.account = account
self.timeout = timeout self.timeout = timeout
...@@ -30,7 +26,14 @@ ...@@ -30,7 +26,14 @@
self.account = account self.account = account
self.timeout = timeout self.timeout = timeout
self.session = requests.sessions.Session() if server_url.startswith("/"):
self.session = requests_unixsocket.Session()
self.server_url = "http+unix://{}/api/".format(
quote(server_url, safe="")
)
else:
self.session = requests.sessions.Session()
self.server_url = server_url
self.templates = Templates(self) self.templates = Templates(self)
def call(self, path, http_verb="post", **params): def call(self, path, http_verb="post", **params):
...@@ -34,7 +37,7 @@ ...@@ -34,7 +37,7 @@
self.templates = Templates(self) self.templates = Templates(self)
def call(self, path, http_verb="post", **params): def call(self, path, http_verb="post", **params):
"""Call redner with the specified paramters. """Call redner with the specified parameters.
Delegate to ``call_impl``; this is a wrapper to have some retries Delegate to ``call_impl``; this is a wrapper to have some retries
before giving up as redner sometimes mistakenly rejects our queries. before giving up as redner sometimes mistakenly rejects our queries.
""" """
...@@ -62,7 +65,9 @@ ...@@ -62,7 +65,9 @@
if not self.server_url: if not self.server_url:
raise ValidationError( raise ValidationError(
"Cannot find redner config url. " _(
"Please add it in odoo.conf or in ir.config_parameter" "Cannot find redner config url. "
"Please add it in odoo.conf or in ir.config_parameter"
)
) )
...@@ -67,6 +72,6 @@ ...@@ -67,6 +72,6 @@
) )
url = urljoin(self.server_url, path) url = self.server_url + path
_http_verb = http_verb.upper() _http_verb = http_verb.upper()
_logger.info("Redner: Calling %s...", _http_verb) _logger.info("Redner: Calling %s...", _http_verb)
...@@ -92,7 +97,7 @@ ...@@ -92,7 +97,7 @@
response = r.json() response = r.json()
except Exception: except Exception:
# If we cannot decode JSON then it's an API error # If we cannot decode JSON then it's an API error
# having response as text could help debuggin with sentry # having response as text could help debugging with sentry
response = r.text response = r.text
if not str(r.status_code).startswith("2"): if not str(r.status_code).startswith("2"):
......
requests_unixsocket
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