Skip to content
Permalink
Browse files

[ADD] configurable scheme, host and http auth

  • Loading branch information...
nilshamerlinck authored and sebalix committed Jun 11, 2017
1 parent aa0939e commit f8c64bc6a3007d7de171b5b60563cf7ede863f86
Showing with 39 additions and 7 deletions.
  1. +10 −1 connector/jobrunner/__init__.py
  2. +29 −6 connector/jobrunner/runner.py
@@ -42,7 +42,16 @@
def run():
# sleep a bit to let the workers start at ease
time.sleep(START_DELAY)
scheme = os.environ.get('ODOO_CONNECTOR_SCHEME') or 'http'
host = os.environ.get('ODOO_CONNECTOR_HOST') or config['xmlrpc_interface']
port = os.environ.get('ODOO_CONNECTOR_PORT') or config['xmlrpc_port']
user = os.environ.get('ODOO_CONNECTOR_HTTP_AUTH_USER')
password = os.environ.get('ODOO_CONNECTOR_HTTP_AUTH_PASSWORD')
channels = os.environ.get('ODOO_CONNECTOR_CHANNELS')
runner = ConnectorRunner(port or 8069, channels or 'root:1')
runner = ConnectorRunner(scheme,
host or 'localhost',
port or 8069,
user,
password,
channels or 'root:1')
runner.run_forever()
@@ -54,7 +54,11 @@
* Set the following environment variables:
- ODOO_CONNECTOR_CHANNELS=root:4 (or any other channels configuration)
- optional: ODOO_CONNECTOR_SCHEME=http
- optional if xmlrpc_interface is not set: ODOO_CONNECTOR_HOST=localhost
- optional if xmlrpc_port is not set: ODOO_CONNECTOR_PORT=8069
- optional: ODOO_CONNECTOR_HTTP_AUTH_USER and
ODOO_CONNECTOR_HTTP_AUTH_PASSWORD
* Start Odoo with --workers > 1. [2]
* Disable then "Enqueue Jobs" cron.
@@ -98,7 +102,7 @@
_logger = logging.getLogger(__name__)


def _async_http_get(port, db_name, job_uuid):
def _async_http_get(scheme, host, port, user, password, db_name, job_uuid):
# Method to set failed job (due to timeout, etc) as pending,
# to avoid keeping it as enqueued.
def set_job_pending():
@@ -115,12 +119,15 @@ def set_job_pending():
# if this was python3 I would be doing this with
# asyncio, aiohttp and aiopg
def urlopen():
url = ('http://localhost:%s/connector/runjob?db=%s&job_uuid=%s' %
(port, db_name, job_uuid))
url = ('%s://%s:%s/connector/runjob?db=%s&job_uuid=%s' %
(scheme, host, port, db_name, job_uuid))
try:
auth = None
if user:
auth = (user, password)
# we are not interested in the result, so we set a short timeout
# but not too short so we trap and log hard configuration errors
requests.get(url, timeout=1)
requests.get(url, timeout=1, auth=auth)
except requests.Timeout:
set_job_pending()
except:
@@ -220,8 +227,18 @@ def set_job_enqueued(self, uuid):

class ConnectorRunner(object):

def __init__(self, port=8069, channel_config_string='root:1'):
def __init__(self,
scheme='http',
host='localhost',
port=8069,
user=None,
password=None,
channel_config_string='root:1'):
self.scheme = scheme
self.host = host
self.port = port
self.user = user
self.password = password
self.channel_manager = ChannelManager()
self.channel_manager.simple_configure(channel_config_string)
self.db_by_name = {}
@@ -265,7 +282,13 @@ def run_jobs(self):
_logger.info("asking Odoo to run job %s on db %s",
job.uuid, job.db_name)
self.db_by_name[job.db_name].set_job_enqueued(job.uuid)
_async_http_get(self.port, job.db_name, job.uuid)
_async_http_get(self.scheme,
self.host,
self.port,
self.user,
self.password,
job.db_name,
job.uuid)

def process_notifications(self):
for db in self.db_by_name.values():

0 comments on commit f8c64bc

Please sign in to comment.
You can’t perform that action at this time.