Skip to content
Open
Show file tree
Hide file tree
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
31 changes: 20 additions & 11 deletions queue_job/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

=========
Job Queue
=========
Expand All @@ -17,7 +13,7 @@ Job Queue
.. |badge1| image:: https://img.shields.io/badge/maturity-Mature-brightgreen.png
:target: https://odoo-community.org/page/development-status
:alt: Mature
.. |badge2| image:: https://img.shields.io/badge/license-LGPL--3-blue.png
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fqueue-lightgray.png?logo=github
Expand Down Expand Up @@ -99,10 +95,15 @@ Configuration

- ``ODOO_QUEUE_JOB_CHANNELS=root:4`` or any other channels
configuration. The default is ``root:1``
- if ``xmlrpc_port`` is not set: ``ODOO_QUEUE_JOB_PORT=8069``

- Start Odoo with ``--load=web,queue_job`` and ``--workers`` greater
than 1. [1]_
- ``ODOO_QUEUE_JOB_PORT=8069``, default ``--http-port``
- ``ODOO_QUEUE_JOB_SCHEME=https``, default ``http``
- ``ODOO_QUEUE_JOB_HOST=load-balancer``, default
``--http-interface`` or ``localhost`` if unset
- ``ODOO_QUEUE_JOB_HTTP_AUTH_USER=jobrunner``, default empty
- ``ODOO_QUEUE_JOB_HTTP_AUTH_PASSWORD=s3cr3t``, default empty
- ``QUEUE_JOB__NO_DELAY=1``, disables the queue for testing purposes
- Start Odoo with ``--load=web,queue_job`` and ``--workers`` greater
than 1. [1]_

- Using the Odoo configuration file:

Expand All @@ -116,6 +117,12 @@ Configuration
(...)
[queue_job]
channels = root:2
scheme = https
host = load-balancer
port = 443
http_auth_user = jobrunner
http_auth_password = s3cr3t
queue_job__no_delay=True # disables the queue

- Confirm the runner is starting correctly by checking the odoo log
file:
Expand Down Expand Up @@ -442,7 +449,8 @@ running Odoo**
When you are developing (ie: connector modules) you might want to bypass
the queue job and run your code immediately.

To do so you can set QUEUE_JOB\__NO_DELAY=1 in your environment.
To do so you can set QUEUE_JOB\__NO_DELAY=1 in your environment, or
include queue_job\__no_delay=True in your Odoo server configuration.

**Bypass jobs in tests**

Expand Down Expand Up @@ -560,7 +568,8 @@ calling ``jobs_tester.perform_enqueued_jobs()`` in your test.
When you are developing (ie: connector modules) you might want to bypass
the queue job and run your code immediately.

To do so you can set ``QUEUE_JOB__NO_DELAY=1`` in your environment.
To do so you can set ``QUEUE_JOB__NO_DELAY=1`` in your environment, or
include queue_job\__no_delay=True in your Odoo server configuration.

Warning

Expand Down
106 changes: 1 addition & 105 deletions queue_job/jobrunner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,111 +16,7 @@
* It maintains an in-memory priority queue of jobs that
is populated from the queue_job tables in all databases.
* It does not run jobs itself, but asks Odoo to run them through an
anonymous ``/queue_job/runjob`` HTTP request. [1]_

How to use it?
--------------

* Optionally adjust your configuration through environment variables:

- ``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 ``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.
- ``ODOO_QUEUE_JOB_JOBRUNNER_DB_USER=userdb``, default ``db_user``
or ``False`` if unset.
- ``ODOO_QUEUE_JOB_JOBRUNNER_DB_PASSWORD=passdb``, default ``db_password``
or ``False`` if unset.

* Alternatively, configure the channels through the Odoo configuration
file, like:

.. code-block:: ini

[queue_job]
channels = root:4
scheme = https
host = load-balancer
port = 443
http_auth_user = jobrunner
http_auth_password = s3cr3t
jobrunner_db_host = master-db
jobrunner_db_port = 5432
jobrunner_db_user = userdb
jobrunner_db_password = passdb

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

.. code-block:: ini

[odoo]
recipe = anybox.recipe.odoo
(...)
queue_job.channels = root:4
queue_job.scheme = https
queue_job.host = load-balancer
queue_job.port = 443
queue_job.http_auth_user = jobrunner
queue_job.http_auth_password = s3cr3t

* Start Odoo with ``--load=web,web_kanban,queue_job``
and ``--workers`` greater than 1 [2]_, or set the ``server_wide_modules``
option in The Odoo configuration file:

.. code-block:: ini

[options]
(...)
workers = 4
server_wide_modules = web,web_kanban,queue_job
(...)

* Or, if using ``anybox.recipe.odoo``:

.. code-block:: ini

[odoo]
recipe = anybox.recipe.odoo
(...)
options.workers = 4
options.server_wide_modules = web,web_kanban,queue_job

* Confirm the runner is starting correctly by checking the odoo log file:

.. code-block:: none

...INFO...queue_job.jobrunner.runner: starting
...INFO...queue_job.jobrunner.runner: initializing database connections
...INFO...queue_job.jobrunner.runner: queue job runner ready for db <dbname>
...INFO...queue_job.jobrunner.runner: database connections ready

* Create jobs (eg using base_import_async) and observe they
start immediately and in parallel.

* Tip: to enable debug logging for the queue job, use
``--log-handler=odoo.addons.queue_job:DEBUG``

Caveat
------

* After creating a new database or installing queue_job on an
existing database, Odoo must be restarted for the runner to detect it.

.. rubric:: Footnotes

.. [1] From a security standpoint, it is safe to have an anonymous HTTP
request because this request only accepts to run jobs that are
enqueued.
.. [2] It works with the threaded Odoo server too, although this way
of running Odoo is obviously not for production purposes.
anonymous ``/queue_job/runjob`` HTTP request.
"""

import logging
Expand Down
18 changes: 15 additions & 3 deletions queue_job/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
- Adjust environment variables (optional):
- `ODOO_QUEUE_JOB_CHANNELS=root:4` or any other channels
configuration. The default is `root:1`
- if `xmlrpc_port` is not set: `ODOO_QUEUE_JOB_PORT=8069`
- Start Odoo with `--load=web,queue_job` and `--workers` greater than
1.[^1]
- `ODOO_QUEUE_JOB_PORT=8069`, default `--http-port`
- `ODOO_QUEUE_JOB_SCHEME=https`, default `http`
- `ODOO_QUEUE_JOB_HOST=load-balancer`, default `--http-interface`
or `localhost` if unset
- `ODOO_QUEUE_JOB_HTTP_AUTH_USER=jobrunner`, default empty
- `ODOO_QUEUE_JOB_HTTP_AUTH_PASSWORD=s3cr3t`, default empty
- `QUEUE_JOB__NO_DELAY=1`, disables the queue for testing purposes
- Start Odoo with `--load=web,queue_job` and `--workers` greater than
1.[^1]
- Using the Odoo configuration file:

``` ini
Expand All @@ -16,6 +22,12 @@ server_wide_modules = web,queue_job
(...)
[queue_job]
channels = root:2
scheme = https
host = load-balancer
port = 443
http_auth_user = jobrunner
http_auth_password = s3cr3t
queue_job__no_delay=True # disables the queue
```

- Confirm the runner is starting correctly by checking the odoo log
Expand Down
6 changes: 4 additions & 2 deletions queue_job/readme/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ running Odoo**
When you are developing (ie: connector modules) you might want to bypass
the queue job and run your code immediately.

To do so you can set QUEUE_JOB\_\_NO_DELAY=1 in your environment.
To do so you can set QUEUE_JOB\_\_NO_DELAY=1 in your environment,
or include queue_job__no_delay=True in your Odoo server configuration.

**Bypass jobs in tests**

Expand Down Expand Up @@ -407,7 +408,8 @@ def test_method_to_test(self):
When you are developing (ie: connector modules) you might want to bypass
the queue job and run your code immediately.

To do so you can set `QUEUE_JOB__NO_DELAY=1` in your environment.
To do so you can set `QUEUE_JOB__NO_DELAY=1` in your environment,
or include queue_job__no_delay=True in your Odoo server configuration.

Warning

Expand Down
6 changes: 6 additions & 0 deletions queue_job/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import logging
import os

from .jobrunner import queue_job_config

_logger = logging.getLogger(__name__)


Expand All @@ -19,3 +21,7 @@ def must_run_without_delay(env):
if env.context.get("queue_job__no_delay"):
_logger.info("`queue_job__no_delay` ctx key found. NO JOB scheduled.")
return True

if queue_job_config.get("queue_job__no_delay"):
_logger.info("`queue_job__no_delay` server config found. NO JOB scheduled.")
return True