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
Tags 11.0.2.8.0
1 merge request!19forward port of 11.0 features
......@@ -5,6 +5,11 @@
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)
* Configurable timeout for redner calls, default is 20 seconds.
......
======
Redner
======
......
......@@ -34,5 +34,6 @@
"views/report_redner.xml",
"views/menu.xml",
],
"external_dependencies": {"python": ["requests_unixsocket"]},
"demo": [],
}
import logging
import time
from urllib.parse import quote
import requests
from odoo import _
from odoo.exceptions import ValidationError
......@@ -3,14 +4,10 @@
import requests
from odoo import _
from odoo.exceptions import ValidationError
try:
from urllib.parse import urljoin
except ImportError:
from urlparse import urljoin
import requests_unixsocket
_logger = logging.getLogger(__name__)
......@@ -21,8 +18,8 @@
Args:
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.
"""
self.api_key = api_key
......@@ -25,8 +22,7 @@
timeout(float): Timeout per Redner call, in seconds.
"""
self.api_key = api_key
self.server_url = server_url
self.account = account
self.timeout = timeout
......@@ -30,7 +26,14 @@
self.account = account
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)
def call(self, path, http_verb="post", **params):
......@@ -34,7 +37,7 @@
self.templates = Templates(self)
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
before giving up as redner sometimes mistakenly rejects our queries.
"""
......@@ -62,7 +65,9 @@
if not self.server_url:
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 @@
)
url = urljoin(self.server_url, path)
url = self.server_url + path
_http_verb = http_verb.upper()
_logger.info("Redner: Calling %s...", _http_verb)
......@@ -92,7 +97,7 @@
response = r.json()
except Exception:
# 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
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