Search 1.9 billion lines of Odoo code on GitHub

queue_job

Author: Camptocamp,ACSONE SA/NV,Odoo Community Association (OCA)
License: LGPL-3
Branch: 13.0
Repository: NeatNerdPrime/queue
Dependencies: mail
Languages: HTML (522, 13.6%), PO File (563, 14.7%), Python (1979, 51.6%), SVG (136, 3.5%), XML (422, 11.0%), and reStructuredText (214, 5.6%)
Other branches: 10.0, 11.0, and 12.0
Other repositories: 001101/queue, 2FM/queue, ACCOMODATA-BVBA/queue, AITIC/queue, Alfa-90/queue, App247/queue, Callino/queue, Change2improve/queue, ChinaShrimp/queue, Comunitea/queue, DamonLiu0814/queue, Dhirendrasinh-SerpentCS/queue, Dhrupesh/queue, Digital5-Odoo/queue, ERPLibre/queue, ForgeFlow/queue, GSLabIt/queue, Gabinete-Digital/queue, Ingeos/queue, Jarsa/queue, KolushovAlexandr/queue, Leuan12/queue, MadsackMediaStore/queue, MathBenTech/queue, MediaJockey/queue, Miller-Media/connector, MjAbuz/queue, NachoAlesLopez/queue, Numigi/queue, OCA-MUK/queue, OCA/queue, OpenAT/queue, PrenorSistemas/queue, RRRoger/queue, RSC-TECHNOLOGY-CI/queue, RealSolutionsLux/queue, SanteLibre/queue, SequarSrl/queue, SeuMarco/queue, SuperMeepBoy/queue, Syci-Consulting/queue, TDu/queue, TRESCLOUD/queue, Tatider/queue, Tecnativa/queue, Trust-Code/queue, VCLS-org/queue, Vauxoo/queue, VisiionSolucionesTecnologicas/queue, Vkuruganti/queue, acsone/queue, acysos/odoo-addons, akretion/queue, algiopensource/queue, alsor62/queue, altanmur/queue, amendoncabh/queue, anggadjava/queue, anhvu-sg/queue, apachesep/queue, apertoso/queue, apetbiz/queue, apineux/queue, atchuthan/queue, aurestic/queue, bishalgit/queue, blueoceandevops/queue, bmya/queue, bobslee/queue, boskowski/odoo_oca_queue, brain-tec/queue, bvkl/queue, camptocamp/queue, celm1990/queue, cocox/queue, cogitoweb/queue, consultingerp/odoo-addons-2, contineolabs/queue, coopdevs/odoo-addons, coopiteasy/queue, csveda/queue, dave-prosee/queue-from-magnus, dev00007/queue, diggy128/queue, dndoanh/queue, dong-z/queue, druidoo-dev/queue, dynapps/queue, ecosoft-odoo/queue, ecosoft-odoo/rjc, eezee-it/queue, egbonrelu/queue, ehsu0407/queue, em230418/queue, emiproenterprise/queue, eneldoserrata/queue, eslammohamed13/odoo-addons, etobella/queue, exosoftware/oca-queue, factorlibre/queue, fengzoo2018/queue, florian-dacosta/queue, fr33co/queue, glovebx/queue, guewen/connector, guewen/queue, guwenfeng/queue, haroldtamo/queue, hibou-io/oca-queue, hinfo506/queue, hpatelserpentcs/queue, hq8399/queue, hustlercoder/queue, hzwzw/queue, igor-mitin/queue, ilyasbahridudak/queue, isoscl/queue, jsilvestar/queue, kevin070982/odoo-project-10.0, kingofsevens/queue, kit9/odoo-addons-1, leanhtuan1996/queue, lepistone/queue, libregob/queue, lideritjnma/queue, limingsichuan/queue, lincersolucoes/oca-queue, liweijie0812/queue, loftwah/queue, lonelyleaves/queue, lonelysun/queue, magnuscolors/queue, marcelsavegnago/odoo-addons, marcelsavegnago/queue, mauraco-group/queue, maykonAguiar/queue, mozaik-association/queue, nadiaafa/queue, nilshamerlinck/queue, nodoo/queue, omalbastin/queue, one2pret/queue, ontruck/queue, phatdo-novobi/queue, popcomputadores-desenv/queue, praxigento/oca-queue, profumang/queue, pscloud/queue, qtheuret/queue, raizs/queue, rlfss/queue, rodrig92/odoo-addons-1, royalline1/queue, sahil-navadiya/queue, samuel-fringeli/queue, sanube/queue, sc4you/queue, sewisoft/queue, shengyf1/queue, shepilov-vladislav/queue, simahawk/queue, sotsam/queue, steingabelgaard/queue, stephen144/queue, subteno-it/queue, sunflowerit/queue, sunshineLhj/queue, tajawal/queue, takinobori/oca-queue, tandrieuxx/queue, tarteo/queue, tegin/queue, telesoho/queue, thanhchatvn/queue, thanhchatvn/saas-addons, themreza/queue, thinkopensolutions/oca-queue, thoongnv/queue, tirma-sa/queue, traviswaelbro/queue, tuannguyen-itit/queue, unitek-solusi/OCA-queue, ursais/queue, versada/queue, vijay-erpharbor/queue, vinaybhawsar/queue, vjd8866/queue, vnsofthe/queue, vrenaville/queue, wahello/acysos-odoo-addons, westlyou/queue-1, wjshan/queue, wty0512/queue, x0rzkov/odoo-queue, xcgd/queue, xwh123807/queue, yangshii/queue, yucer/queue, zakiuu/queue, and zhaowenzhe/queue

<h1 class="title">Job Queue</h1> <p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Mature" src="https://img.shields.io/badge/maturity-Mature-brightgreen.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/queue/tree/13.0/queue_job"><img alt="OCA/queue" src="https://img.shields.io/badge/github-OCA%2Fqueue-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/queue-13-0/queue-13-0-queue_job"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/230/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p> <p>This addon adds an integrated Job Queue to Odoo.</p> <p>It allows to postpone method calls executed asynchronously.</p> <p>Jobs are executed in the background by a <code>Jobrunner</code>, in their own transaction.</p> <p>Example:</p> <pre> <code lang="python">from odoo import models, fields, api from odoo.addons.queue_job.job import job class MyModel(models.Model): _name = 'my.model' &#64;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' def button_do_stuff(self): self.env['my.model'].with_delay().my_method('a', k=2)</code> </pre> <p>In the snippet of code above, when we call <code>button_do_stuff</code>, 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.</p> <p>Features:</p> <ul class="simple"> <li>Views for jobs, jobs are stored in PostgreSQL</li> <li>Jobrunner: execute the jobs, highly efficient thanks to PostgreSQL's NOTIFY</li> <li>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.</li> <li>Retries: Ability to retry jobs by raising a type of exception</li> <li>Retry Pattern: the 3 first tries, retry after 10 seconds, the 5 next tries, retry after 1 minutes, ...</li> <li>Job properties: priorities, estimated time of arrival (ETA), custom description, number of retries</li> <li>Related Actions: link an action on the job view, such as open the record concerned by the job</li> </ul> <p><strong>Table of contents</strong></p> <div class="contents local topic" id="contents"> <ul class="simple"> <li><a class="reference internal" href="#installation" id="id7">Installation</a></li> <li><a class="reference internal" href="#configuration" id="id8">Configuration</a></li> <li><a class="reference internal" href="#usage" id="id9">Usage</a><ul> <li><a class="reference internal" href="#developers" id="id10">Developers</a></li> </ul> </li> <li><a class="reference internal" href="#known-issues-roadmap" id="id11">Known issues / Roadmap</a></li> <li><a class="reference internal" href="#changelog" id="id12">Changelog</a><ul> <li><a class="reference internal" href="#next" id="id13">Next</a></li> <li><a class="reference internal" href="#id3" id="id14">13.0.1.2.0 (2020-03-10)</a></li> <li><a class="reference internal" href="#id4" id="id15">13.0.1.1.0 (2019-11-01)</a></li> <li><a class="reference internal" href="#id6" id="id16">13.0.1.0.0 (2019-10-14)</a></li> </ul> </li> <li><a class="reference internal" href="#bug-tracker" id="id17">Bug Tracker</a></li> <li><a class="reference internal" href="#credits" id="id18">Credits</a><ul> <li><a class="reference internal" href="#authors" id="id19">Authors</a></li> <li><a class="reference internal" href="#contributors" id="id20">Contributors</a></li> <li><a class="reference internal" href="#maintainers" id="id21">Maintainers</a></li> </ul> </li> </ul> </div> <a name="installation"></a> <h2><a class="toc-backref" href="#id7">Installation</a></h2> <p>Be sure to have the <code>requests</code> library.</p> <a name="configuration"></a> <h2><a class="toc-backref" href="#id8">Configuration</a></h2> <ul class="simple"> <li>Using environment variables and command line:<ul> <li>Adjust environment variables (optional):<ul> <li><code>ODOO_QUEUE_JOB_CHANNELS=root:4</code> or any other channels configuration. The default is <code>root:1</code></li> <li>if <code>xmlrpc_port</code> is not set: <code>ODOO_QUEUE_JOB_PORT=8069</code></li> </ul> </li> <li>Start Odoo with <code>--load=web,queue_job</code> and <code>--workers</code> greater than 1. <a class="footnote-reference" href="#id2" id="id1">[1]</a></li> </ul> </li> <li>Using the Odoo configuration file:</li> </ul> <pre> <code lang="ini">[options] (...) workers = 6 server_wide_modules = web,queue_job (...) [queue_job] channels = root:2</code> </pre> <ul class="simple"> <li>Confirm the runner is starting correctly by checking the odoo log file:</li> </ul> <pre class="code"> <code class="code">...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 &lt;dbname&gt; ...INFO...queue_job.jobrunner.runner: database connections ready</code> </pre> <ul class="simple"> <li>Create jobs (eg using <code>base_import_async</code>) and observe they start immediately and in parallel.</li> <li>Tip: to enable debug logging for the queue job, use <code>--log-handler=odoo.addons.queue_job:DEBUG</code></li> </ul> <table class="docutils footnote" frame="void" id="id2" rules="none"> <colgroup><col class="label" /><col /></colgroup> <tbody valign="top"> <tr><td class="label"><a class="fn-backref" href="#id1">[1]</a></td><td>It works with the threaded Odoo server too, although this way of running Odoo is obviously not for production purposes.</td></tr> </tbody> </table> <a name="usage"></a> <h2><a class="toc-backref" href="#id9">Usage</a></h2> <p>To use this module, you need to:</p> <ol class="arabic simple"> <li>Go to <code>Job Queue</code> menu</li> </ol> <a name="developers"></a> <h3><a class="toc-backref" href="#id10">Developers</a></h3> <p><strong>Bypass jobs on running Odoo</strong></p> <p>When you are developing (ie: connector modules) you might want to bypass the queue job and run your code immediately.</p> <p>To do so you can set <cite>TEST_QUEUE_JOB_NO_DELAY=1</cite> in your enviroment.</p> <p><strong>Bypass jobs in tests</strong></p> <p>When writing tests on job-related methods is always tricky to deal with delayed recordsets. To make your testing life easier you can set <cite>test_queue_job_no_delay=True</cite> in the context.</p> <p>Tip: you can do this at test case level like this</p> <pre> <code lang="python">&#64;classmethod def setUpClass(cls): super().setUpClass() cls.env = cls.env(context=dict( cls.env.context, test_queue_job_no_delay=True, # no jobs thanks ))</code> </pre> <p>Then all your tests execute the job methods synchronously without delaying any jobs.</p> <a name="known-issues-roadmap"></a> <h2><a class="toc-backref" href="#id11">Known issues / Roadmap</a></h2> <ul class="simple"> <li>After creating a new database or installing <code>queue_job</code> on an existing database, Odoo must be restarted for the runner to detect it.</li> <li>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 <code>started</code> or <code>enqueued</code> 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 <em>before starting Odoo</em>:</li> </ul> <pre> <code lang="sql">update queue_job set state='pending' where state in ('started', 'enqueued')</code> </pre> <a name="changelog"></a> <h2><a class="toc-backref" href="#id12">Changelog</a></h2> <a name="next"></a> <h3><a class="toc-backref" href="#id13">Next</a></h3> <ul class="simple"> <li>[ADD] Run jobrunner as a worker process instead of a thread in the main process (when running with --workers &gt; 0)</li> </ul> <a name="id3"></a> <h3><a class="toc-backref" href="#id14">13.0.1.2.0 (2020-03-10)</a></h3> <ul class="simple"> <li>Fix Multi-company access rules</li> </ul> <a name="id4"></a> <h3><a class="toc-backref" href="#id15">13.0.1.1.0 (2019-11-01)</a></h3> <p>Important: the license has been changed from AGPL3 to LGPL3.</p> <ul class="simple"> <li>Remove deprecated default company method (details on <a class="reference external" href="https://github.com/OCA/queue/pull/180">#180</a>)</li> </ul> <a name="id6"></a> <h3><a class="toc-backref" href="#id16">13.0.1.0.0 (2019-10-14)</a></h3> <ul class="simple"> <li>[MIGRATION] from 12.0 branched at rev. 0138cd0</li> </ul> <a name="bug-tracker"></a> <h2><a class="toc-backref" href="#id17">Bug Tracker</a></h2> <p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/queue/issues">GitHub Issues</a>. 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 <a class="reference external" href="https://github.com/OCA/queue/issues/new?body=module:%20queue_job%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p> <p>Do not contact contributors directly about support or help with technical issues.</p> <a name="credits"></a> <h2><a class="toc-backref" href="#id18">Credits</a></h2> <a name="authors"></a> <h3><a class="toc-backref" href="#id19">Authors</a></h3> <ul class="simple"> <li>Camptocamp</li> <li>ACSONE SA/NV</li> </ul> <a name="contributors"></a> <h3><a class="toc-backref" href="#id20">Contributors</a></h3> <ul class="simple"> <li>Guewen Baconnier &lt;<a class="reference external" href="mailto:guewen.baconnier&#64;camptocamp.com">guewen.baconnier&#64;camptocamp.com</a>&gt;</li> <li>Stéphane Bidoul &lt;<a class="reference external" href="mailto:stephane.bidoul&#64;acsone.eu">stephane.bidoul&#64;acsone.eu</a>&gt;</li> <li>Matthieu Dietrich &lt;<a class="reference external" href="mailto:matthieu.dietrich&#64;camptocamp.com">matthieu.dietrich&#64;camptocamp.com</a>&gt;</li> <li>Jos De Graeve &lt;<a class="reference external" href="mailto:Jos.DeGraeve&#64;apertoso.be">Jos.DeGraeve&#64;apertoso.be</a>&gt;</li> <li>David Lefever &lt;<a class="reference external" href="mailto:dl&#64;taktik.be">dl&#64;taktik.be</a>&gt;</li> <li>Laurent Mignon &lt;<a class="reference external" href="mailto:laurent.mignon&#64;acsone.eu">laurent.mignon&#64;acsone.eu</a>&gt;</li> <li>Laetitia Gangloff &lt;<a class="reference external" href="mailto:laetitia.gangloff&#64;acsone.eu">laetitia.gangloff&#64;acsone.eu</a>&gt;</li> <li>Cédric Pigeon &lt;<a class="reference external" href="mailto:cedric.pigeon&#64;acsone.eu">cedric.pigeon&#64;acsone.eu</a>&gt;</li> <li>Tatiana Deribina &lt;<a class="reference external" href="mailto:tatiana.deribina&#64;avoin.systems">tatiana.deribina&#64;avoin.systems</a>&gt;</li> </ul> <a name="maintainers"></a> <h3><a class="toc-backref" href="#id21">Maintainers</a></h3> <p>This module is maintained by the OCA.</p> <a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a> <p>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.</p> <p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p> <p><a class="reference external" href="https://github.com/guewen"><img alt="guewen" src="https://github.com/guewen.png?size=40px" /></a></p> <p>This module is part of the <a class="reference external" href="https://github.com/OCA/queue/tree/13.0/queue_job">OCA/queue</a> project on GitHub.</p> <p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>