Skip to main content

Job Queue

Project description

Mature License: LGPL-3 OCA/queue Translate me on Weblate Try me on Runbot

This addon adds an integrated Job Queue to Odoo.

It allows to postpone method calls executed asynchronously.

Jobs are executed in the background by a Jobrunner, in their own transaction.

Example:

from odoo import models, fields, api
from odoo.addons.queue_job.job import job

class MyModel(models.Model):
   _name = 'my.model'

   @api.multi
   @job
   def my_method(self, a, k=None):
       _logger.info('executed with a: %s and k: %s', a, k)


class MyOtherModel(models.Model):
    _name = 'my.other.model'

    @api.multi
    def button_do_stuff(self):
        self.env['my.model'].with_delay().my_method('a', k=2)

In the snippet of code above, when we call button_do_stuff, a job capturing the method and arguments will be postponed. It will be executed as soon as the Jobrunner has a free bucket, which can be instantaneous if no other job is running.

Features:

  • Views for jobs, jobs are stored in PostgreSQL

  • Jobrunner: execute the jobs, highly efficient thanks to PostgreSQL’s NOTIFY

  • Channels: give a capacity for the root channel and its sub-channels and segregate jobs in them. Allow for instance to restrict heavy jobs to be executed one at a time while little ones are executed 4 at a times.

  • Retries: Ability to retry jobs by raising a type of exception

  • Retry Pattern: the 3 first tries, retry after 10 seconds, the 5 next tries, retry after 1 minutes, …

  • Job properties: priorities, estimated time of arrival (ETA), custom description, number of retries

  • Related Actions: link an action on the job view, such as open the record concerned by the job

Table of contents

Installation

Be sure to have the requests library.

Configuration

  • Using environment variables and command line:

    • 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,web_kanban,queue_job and --workers greater than 1. [1]

  • Using the Odoo configuration file:

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

(...)
[queue_job]
channels = root:2
  • Confirm the runner is starting correctly by checking the odoo log file:

...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

Usage

To use this module, you need to:

  1. Go to Job Queue menu

Developers

Bypass jobs on 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 TEST_QUEUE_JOB_NO_DELAY=1 in your enviroment.

Bypass jobs in tests

When writing tests on job-related methods is always tricky to deal with delayed recordsets. To make your testing life easier you can set test_queue_job_no_delay=True in the context.

Tip: you can do this at test case level like this

@classmethod
def setUpClass(cls):
    super().setUpClass()
    cls.env = cls.env(context=dict(
        cls.env.context,
        test_queue_job_no_delay=True,  # no jobs thanks
    ))

Then all your tests execute the job methods synchronously without delaying any jobs.

Known issues / Roadmap

  • After creating a new database or installing queue_job 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 or enqueued 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')

Changelog

Next

  • [IMP] Dont’ start the Jobrunner if root channel’s capacity is explicitly set to 0 (backport from #148)

  • [ADD] Default “related action” for jobs, opening a form or list view (when the job is linked to respectively one record on several). (#79, backport from #46)

10.0.1.0.0

  • Starting the changelog from there

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed feedback.

Do not contact contributors directly about support or help with technical issues.

Credits

Authors

  • Camptocamp

  • ACSONE SA/NV

Contributors

Maintainers

This module is maintained by the OCA.

Odoo Community Association

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

Current maintainer:

guewen

This module is part of the OCA/queue project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

File details

Details for the file odoo10_addon_queue_job-10.0.1.2.0-py2-none-any.whl.

File metadata

  • Download URL: odoo10_addon_queue_job-10.0.1.2.0-py2-none-any.whl
  • Upload date:
  • Size: 72.1 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.7.3

File hashes

Hashes for odoo10_addon_queue_job-10.0.1.2.0-py2-none-any.whl
Algorithm Hash digest
SHA256 71fa9e65dd026bca93d6c6f342ea3ed8d7182e97c6cb94ed616899875b35d16c
MD5 603a4d5d876c5907b4429dfe8194b916
BLAKE2b-256 ba1f390474e1da0b6678b28a05975a4b3416e1197583617a7d2a0184701df00a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page