Job Runner¶
This is the API documentation for the job runner.
These classes are not intended for use by module developers.
What is the job runner?¶
The job runner is the main process managing the dispatch of delayed jobs to available Odoo workers
How does it work?¶
- It starts as a thread in the Odoo main process
- It receives postgres NOTIFY messages each time jobs are added or updated in the queue_job table.
- 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
/connector/runjob
HTTP request. [1]
How to use it?¶
- By default, the job runner will use Odoo’s configuration:
- connect to Odoo via
- host
xmlrpc_interface
orlocalhost
if unset - portxmlrpc_port
, or8069
if unset - connect to the database via
db_host
anddb_port
- connect to Odoo via
- host
- To adjust these values, you can either use environment variables:
ODOO_CONNECTOR_SCHEME=https
ODOO_CONNECTOR_HOST=load-balancer
ODOO_CONNECTOR_PORT=443
ODOO_CONNECTOR_HTTP_AUTH_USER=connector
ODOO_CONNECTOR_HTTP_AUTH_PASSWORD=s3cr3t
ODOO_CONNECTOR_JOBRUNNER_DB_HOST=master-db
ODOO_CONNECTOR_JOBRUNNER_DB_PORT=5432
- Or alternatively, you can add a
[options-connector]
section in Odoo’s configuration file, like this:
[options-connector]
scheme = https
host = load-balancer
port = 443
http_auth_user = connector
http_auth_password = s3cr3t
jobrunner_db_host = master-db
jobrunner_db_port = 5432
- Start Odoo with
--load=web,web_kanban,connector
and--workers
greater than 1. [2] - Confirm the runner is starting correctly by checking the odoo log file:
...INFO...connector.jobrunner.runner: starting
...INFO...connector.jobrunner.runner: initializing database connections
...INFO...connector.jobrunner.runner: connector runner ready for db <dbname>
...INFO...connector.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 connector, use
--log-handler=openerp.addons.connector:DEBUG
Caveat¶
- After creating a new database or installing connector on an existing database, Odoo must be restarted for the runner to detect it.
- When Odoo shuts down normally, it waits for running jobs to finish.
However, when the Odoo server crashes or is otherwise force-stopped,
running jobs are interrupted while the runner has no chance to know
they have been aborted. In such situations, jobs may remain in
started
orenqueued
state after the Odoo server is halted. Since the runner has no way to know if they are actually running or not, and does not know for sure if it is safe to restart the jobs, it does not attempt to restart them automatically. Such stale jobs therefore fill the running queue and prevent other jobs to start. You must therefore requeue them manually, either from the Jobs view, or by running the following SQL statement before starting Odoo:
update queue_job set state='pending' where state in ('started', 'enqueued')
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. |