Package: odoo11-addon-queue-job
This addon adds an integrated Job Queue to Odoo.It allows to postpone method calls executed asynchronously.Jobs are executed in the background by aJobrunner, in their own transaction.Example:fromodooimportmodels,fields,apifromodoo.addons.queue_job.jobimportjobclassMyModel(models.Model):_name='my.model'@api.multi@jobdefmy_method(self,a,k=None):_logger.info('executed with a:%sand k:%s',a,k)classMyOtherModel(models.Model):_name='my.other.model'@api.multidefbutton_do_stuff(self):self.env['my.model'].with_delay().my_method('a',k=2)In the snippet of code above, when we callbutton_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 PostgreSQLJobrunner: execute the jobs, highly efficient thanks to PostgreSQL’s NOTIFYChannels: 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 exceptionRetry 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 retriesRelated Actions: link an action on the job view, such as open the record
concerned by the jobTable of contentsInstallationConfigurationUsageDevelopersKnown issues / RoadmapChangelogNext11.0.1.1.0 (2018-05-25)Bug TrackerCreditsAuthorsContributorsMaintainersInstallationBe sure to have therequestslibrary.ConfigurationUsing environment variables and command line:Adjust environment variables (optional):ODOO_QUEUE_JOB_CHANNELS=root:4or any other channels configuration.
The default isroot:1ifxmlrpc_portis not set:ODOO_QUEUE_JOB_PORT=8069Start Odoo with--load=web,queue_joband--workersgreater than 1.[1]Using the Odoo configuration file:[options](...)workers=6server_wide_modules=web,queue_job(...)[queue_job]channels=root:2Confirm 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 readyCreate jobs (eg usingbase_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[1]It works with the threaded Odoo server too, although this way
of running Odoo is obviously not for production purposes.UsageTo use this module, you need to:Go toJob QueuemenuDevelopersBypass jobs on running OdooWhen you are developing (ie: connector modules) you might want
to bypass the queue job and run your code immediately.To do so you can setTEST_QUEUE_JOB_NO_DELAY=1in your enviroment.Bypass jobs in testsWhen writing tests on job-related methods is always tricky to deal with
delayed recordsets. To make your testing life easier
you can settest_queue_job_no_delay=Truein the context.Tip: you can do this at test case level like this@classmethoddefsetUpClass(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 / RoadmapAfter creating a new database or installingqueue_jobon 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 instartedorenqueuedstate 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 statementbefore starting Odoo:updatequeue_jobsetstate='pending'wherestatein('started','enqueued')ChangelogNext[IMP] Dont’ start the Jobrunner if root channel’s capacity
is explicitly set to 0[ADD] Ability to set several jobs to done using an multi-action
(port of#59)[REF] Extract a method handling the post of a message when a job is failed,
allowing to modify this behavior from addons[ADD] Default “related action” for jobs, opening a form or list view (when
the job is linked to respectively one record on several).
(#46)[FIX] Error when creating a job channel manually
(#96)11.0.1.1.0 (2018-05-25)[ADD] New neat OCA readme file format
(#71)[ADD] The Jobrunner will keep the same Web Session and no longer generate a
new session per job
(#54)[ADD] Configurable scheme, host and HTTP authentication
(#51)[ADD]base_sparse_fielddoes not longer need to be set in--load(#47)[FIX] Correct automatic registration of channels and job functions
(#69)[FIX] Correct compatibility with@propertymethods
(#50and#69)Bug TrackerBugs are tracked onGitHub 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 welcomedfeedback.Do not contact contributors directly about support or help with technical issues.CreditsAuthorsCamptocampACSONE SA/NVContributorsGuewen Baconnier <guewen.baconnier@camptocamp.com>Stéphane Bidoul <stephane.bidoul@acsone.eu>Matthieu Dietrich <matthieu.dietrich@camptocamp.com>Jos De Graeve <Jos.DeGraeve@apertoso.be>David Lefever <dl@taktik.be>Laurent Mignon <laurent.mignon@acsone.eu>Laetitia Gangloff <laetitia.gangloff@acsone.eu>Cédric Pigeon <cedric.pigeon@acsone.eu>MaintainersThis module is maintained by the OCA.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.Currentmaintainer:This module is part of theOCA/queueproject on GitHub.You are welcome to contribute. To learn how please visithttps://odoo-community.org/page/Contribute.