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
36 changes: 31 additions & 5 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 @@ -85,6 +81,36 @@ Features:
.. contents::
:local:

Use Cases / Context
===================

Odoo treats task synchronously, like when you import a list of products
it will treat each line in one big task. "Queue job" gives you the
ability to detail big tasks in many smaller ones.

Imagine you have a lot of data to change for thousand orders, you can do
it in one step and cause a heavy load on the server, and this may affect
the performance of Odoo. With queue_job you can divide the work in jobs
and run thousand jobs (one job for each orders). An other benefit is if
one line failed it doesn't block the processing of the others, as the
jobs are independent. Plus you can schedule the jobs and set a number of
retries.

Here are some community usage examples:

- Mass sending invoices:
`account_invoice_mass_sending <https://github.com/OCA/account-invoicing/tree/17.0/account_invoice_mass_sending>`__
- Import data in the background:
`base_import_async <https://github.com/OCA/queue/tree/17.0/base_import_async>`__
- Export data in the background:
`base_export_async <https://github.com/OCA/queue/tree/17.0/base_export_async>`__
- Generate contract invoices with jobs:
`contract_queue_job <https://github.com/OCA/contract/tree/17.0/contract_queue_job>`__
- Generate partner invoices with
jobs:`partner_invoicing_mode <https://github.com/OCA/account-invoicing/tree/17.0/partner_invoicing_mode>`__
- Process the Sales Automatic Workflow actions with jobs:
`sale_automatic_workflow_job <https://github.com/OCA/sale-workflow/tree/17.0/sale_automatic_workflow_job>`__

Installation
============

Expand Down
17 changes: 14 additions & 3 deletions queue_job/models/queue_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ def button_done(self):
return True

def button_cancelled(self):
# If job was set to DONE or WAIT_DEPENDENCIES, do not cancel it
states_from = (PENDING, ENQUEUED, FAILED)
# If job was set to DONE do not cancel it
states_from = (WAIT_DEPENDENCIES, PENDING, ENQUEUED, FAILED)
result = _("Cancelled by {}").format(self.env.user.name)
records = self.filtered(lambda job_: job_.state in states_from)
records._change_job_state(CANCELLED, result=result)
Expand All @@ -354,8 +354,11 @@ def _message_post_on_failure(self):
# at every job creation
domain = self._subscribe_users_domain()
base_users = self.env["res.users"].search(domain)
suscribe_job_creator = self._subscribe_job_creator()
for record in self:
users = base_users | record.user_id
users = base_users
if suscribe_job_creator:
users |= record.user_id
record.message_subscribe(partner_ids=users.mapped("partner_id").ids)
msg = record._message_failed_job()
if msg:
Expand All @@ -372,6 +375,14 @@ def _subscribe_users_domain(self):
domain.append(("company_id", "in", companies.ids))
return domain

@api.model
def _subscribe_job_creator(self):
"""
Whether the user that created the job should be subscribed to the job,
in addition to users determined by `_subscribe_users_domain`
"""
return True

def _message_failed_job(self):
"""Return a message which will be posted on the job when it is failed.

Expand Down
15 changes: 15 additions & 0 deletions queue_job/readme/CONTEXT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Odoo treats task synchronously, like when you import a list of products it will treat each line in one big task.
"Queue job" gives you the ability to detail big tasks in many smaller ones.

Imagine you have a lot of data to change for thousand orders, you can do it in one step and cause a heavy load on the server, and this may affect the performance of Odoo. With queue_job you can divide the work in jobs and run thousand jobs (one job for each orders).
An other benefit is if one line failed it doesn't block the processing of the others, as the jobs are independent.
Plus you can schedule the jobs and set a number of retries.

Here are some community usage examples:

* Mass sending invoices: [account_invoice_mass_sending](https://github.com/OCA/account-invoicing/tree/17.0/account_invoice_mass_sending)
* Import data in the background: [base_import_async](https://github.com/OCA/queue/tree/17.0/base_import_async)
* Export data in the background: [base_export_async](https://github.com/OCA/queue/tree/17.0/base_export_async)
* Generate contract invoices with jobs: [contract_queue_job](https://github.com/OCA/contract/tree/17.0/contract_queue_job)
* Generate partner invoices with jobs:[partner_invoicing_mode](https://github.com/OCA/account-invoicing/tree/17.0/partner_invoicing_mode)
* Process the Sales Automatic Workflow actions with jobs: [sale_automatic_workflow_job](https://github.com/OCA/sale-workflow/tree/17.0/sale_automatic_workflow_job)
Loading
Loading