Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions queue_job/jobrunner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@
- ``ODOO_QUEUE_JOB_CHANNELS=root:4`` (or any other channels
configuration), default ``root:1``.
- ``ODOO_QUEUE_JOB_SCHEME=https``, default ``http``.
- ``ODOO_QUEUE_JOB_HOST=load-balancer``, default ``localhost``.
- ``ODOO_QUEUE_JOB_PORT=443``, default ``xmlrpc-port`` or 8069.
- ``ODOO_QUEUE_JOB_HOST=load-balancer``, default ``http_interface``
or ``localhost`` if unset.
- ``ODOO_QUEUE_JOB_PORT=443``, default ``http_port`` or 8069 if unset.
- ``ODOO_QUEUE_JOB_HTTP_AUTH_USER=jobrunner``, default empty.
- ``ODOO_QUEUE_JOB_HTTP_AUTH_PASSWORD=s3cr3t``, default empty.
- ``ODOO_QUEUE_JOB_JOBRUNNER_DB_HOST=master-db``, default ``db_host``
or ``False`` if unset.
- ``ODOO_QUEUE_JOB_JOBRUNNER_DB_PORT=5432``, default ``db_port``
or ``False`` if unset.

* Alternatively, configure the channels through the Odoo configuration
file, like:
Expand All @@ -43,6 +48,8 @@
port = 443
http_auth_user = jobrunner
http_auth_password = s3cr3t
jobrunner_db_host = master-db
jobrunner_db_port = 5432

* Or, if using ``anybox.recipe.odoo``, add this to your buildout configuration:

Expand Down Expand Up @@ -179,21 +186,38 @@ def _odoo_now():
return _datetime_to_epoch(dt)


def _connection_info_for(db_name):
db_or_uri, connection_info = odoo.sql_db.connection_info_for(db_name)

for p in ('host', 'port'):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/p/[key|param]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't mind, I will keep it as it to keep it consistent with the same piece of code that is in the other versions of the module.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, sorry, I missed the original code 😅 👍

cfg = (os.environ.get('ODOO_QUEUE_JOB_JOBRUNNER_DB_%s' % p.upper()) or
config.misc
.get("queue_job", {}).get('jobrunner_db_' + p))

if cfg:
connection_info[p] = cfg

return connection_info


session = requests.Session()


def _async_http_get(scheme, host, port, user, password, db_name, job_uuid):
if not session.cookies:
# obtain an anonymous session
_logger.info("obtaining an anonymous session for the job runner")
url = ('http://localhost:%s/queue_job/session' % (port,))
response = session.get(url, timeout=30)
url = ('%s://%s:%s/queue_job/session' % (scheme, host, port))
auth = None
if user:
auth = (user, password)
response = session.get(url, timeout=30, auth=auth)
response.raise_for_status()

# Method to set failed job (due to timeout, etc) as pending,
# to avoid keeping it as enqueued.
def set_job_pending():
connection_info = odoo.sql_db.connection_info_for(db_name)[1]
connection_info = _connection_info_for(db_name)
conn = psycopg2.connect(**connection_info)
conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
with closing(conn.cursor()) as cr:
Expand Down Expand Up @@ -236,7 +260,7 @@ class Database(object):

def __init__(self, db_name):
self.db_name = db_name
connection_info = odoo.sql_db.connection_info_for(db_name)[1]
connection_info = _connection_info_for(db_name)
self.conn = psycopg2.connect(**connection_info)
self.conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
self.has_queue_job = self._has_queue_job()
Expand Down