-
-
Notifications
You must be signed in to change notification settings - Fork 136
feat(auto-retry) #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat(auto-retry) #75
Changes from all commits
14c7c9a
8015046
67dbc96
38bbf1e
a46c9ac
9e219c6
2347749
5941734
1c5c278
9c365ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,9 @@ | |
|
|
||
| Web controllers of `Odoo` expose two kinds of methods: `json` and `http`. | ||
| These methods can be accessed from the connectors of this module. | ||
|
|
||
| An autoretry for 429 error is also provided, turned on by default | ||
| for *.odoo.com hosts. | ||
| """ | ||
| import sys | ||
|
|
||
|
|
@@ -24,9 +27,25 @@ | |
| class Connector(object): | ||
| """Connector base class defining the interface used | ||
| to interact with a server. | ||
|
|
||
| You can also configure an autoretry (enabled by default for *.odoo.com host) | ||
| using the ``autoretry`` boolean option. If a 429 HTTP error is raised, | ||
| the script will automatically retry after ``backoff_factor * math.pow(2, iteration - 1)`` | ||
|
|
||
| Number of maximum iterations and backoff factor can also be specified using kwargs | ||
| ``autoretry_factor`` default to 0.2 | ||
| ``autoretry_max`` default to 10 | ||
|
|
||
| .. doctest:: | ||
| :options: +SKIP | ||
|
|
||
| >>> import odoorpc | ||
| >>> odoo = odoorpc.ODOO('example.net', port=80, opener=opener, autoretry=True) | ||
| >>> # Or | ||
| >>> odoo = odoorpc.ODOO('example.net', port=80, opener=opener, autoretry=True, autoretry_factor=0.2, autoretry_max=3) | ||
| """ | ||
|
|
||
| def __init__(self, host, port=8069, timeout=120, version=None): | ||
| def __init__(self, host, port=8069, timeout=120, version=None, **kwargs): | ||
| self.host = host | ||
| try: | ||
| int(port) | ||
|
|
@@ -38,6 +57,15 @@ def __init__(self, host, port=8069, timeout=120, version=None): | |
| self.port = int(port) | ||
| self._timeout = timeout | ||
| self.version = version | ||
| # Default autoretry for .odoo.com (saas) hosts | ||
| if 'autoretry' in kwargs: | ||
| self._autoretry = kwargs['autoretry'] | ||
| elif host.endswith('.odoo.com'): | ||
| self._autoretry = True | ||
| else: | ||
| self._autoretry = False | ||
|
Comment on lines
+60
to
+66
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't particularly like this kind of magic. But in case it were, then you can default the Making things obvious and predictable is good IMHO. In any case, this (and the rest of the feature) deserves an entry in the docs. |
||
| self._autoretry_factor = kwargs.get('autoretry_factor', 0.2) | ||
| self._autoretry_max = kwargs.get('autoretry_max', 10) | ||
|
|
||
| @property | ||
| def ssl(self): | ||
|
|
@@ -199,15 +227,19 @@ def __init__( | |
| version=None, | ||
| deserialize=True, | ||
| opener=None, | ||
| **kwargs, | ||
| ): | ||
| super(ConnectorJSONRPC, self).__init__(host, port, timeout, version) | ||
| super(ConnectorJSONRPC, self).__init__( | ||
| host, port, timeout, version, **kwargs | ||
| ) | ||
| self.deserialize = deserialize | ||
| # One URL opener (with cookies handling) shared between | ||
| # JSON and HTTP requests | ||
| if opener is None: | ||
| cookie_jar = CookieJar() | ||
| opener = build_opener(HTTPCookieProcessor(cookie_jar)) | ||
| self._opener = opener | ||
|
|
||
| self._proxy_json, self._proxy_http = self._get_proxies() | ||
|
|
||
| def _get_proxies(self): | ||
|
|
@@ -222,6 +254,9 @@ def _get_proxies(self): | |
| ssl=self.ssl, | ||
| deserialize=self.deserialize, | ||
| opener=self._opener, | ||
| autoretry=self._autoretry, | ||
| autoretry_factor=self._autoretry_factor, | ||
| autoretry_max=self._autoretry_max, | ||
| ) | ||
| proxy_http = jsonrpclib.ProxyHTTP( | ||
| self.host, | ||
|
|
@@ -284,9 +319,10 @@ def __init__( | |
| version=None, | ||
| deserialize=True, | ||
| opener=None, | ||
| **kwargs, | ||
| ): | ||
| super(ConnectorJSONRPCSSL, self).__init__( | ||
| host, port, timeout, version, opener=opener | ||
| host, port, timeout, version, opener=opener, **kwargs | ||
| ) | ||
| self._proxy_json, self._proxy_http = self._get_proxies() | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.