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
113 changes: 113 additions & 0 deletions queue_job_is_running/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
====================
Queue Job Is Running
====================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:09e6da1c23c22c23cef1bd7a94382d7d1229403def5111ede114c21ed49ac853
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fqueue-lightgray.png?logo=github
:target: https://github.com/OCA/queue/tree/18.0/queue_job_is_running
:alt: OCA/queue
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/queue-18-0/queue-18-0-queue_job_is_running
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/queue&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This addon provides the ``queue.job.status.mixin`` mixin. It displays a
warning banner on a form view when the record has one or more
non-terminal queue jobs and lists their names.

The status is read directly from ``queue.job``, so no method is required
to mark a job as running or finished.

**Table of contents**

.. contents::
:local:

Usage
=====

Inherit ``queue.job.status.mixin`` and enqueue the job normally:

.. code:: python

class MyModel(models.Model):
_name = "my.model"
_inherit = ["queue.job.status.mixin"]

def action_process(self):
self.with_delay(
description="Process document",
)._process_in_background()

Set ``description`` to display a user-friendly job name. If it is
omitted, the technical name generated by ``queue_job`` is displayed
instead.

The banner is visible while the job is pending, enqueued, started, or
waiting for dependencies. It disappears automatically when the job is
done, failed, or cancelled.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/queue/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/queue/issues/new?body=module:%20queue_job_is_running%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
-------

* Ecosoft

Contributors
------------

- Saran Lim. <saranl@ecosoft.co.th>

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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.

.. |maintainer-Saran440| image:: https://github.com/Saran440.png?size=40px
:target: https://github.com/Saran440
:alt: Saran440

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-Saran440|

This module is part of the `OCA/queue <https://github.com/OCA/queue/tree/18.0/queue_job_is_running>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions queue_job_is_running/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from . import models
17 changes: 17 additions & 0 deletions queue_job_is_running/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2026 Ecosoft Co., Ltd. (https://ecosoft.co.th)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

{
"name": "Queue Job Is Running",
"version": "18.0.1.0.0",
"author": "Ecosoft, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/queue",
"summary": "Show the queue jobs running for a record",
"license": "AGPL-3",
"category": "Generic Modules",
"depends": ["queue_job"],
"data": [
"templates/running_job_templates.xml",
],
"maintainers": ["Saran440"],
}
4 changes: 4 additions & 0 deletions queue_job_is_running/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from . import queue_job
from . import queue_job_status_mixin
18 changes: 18 additions & 0 deletions queue_job_is_running/models/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2026 Ecosoft Co., Ltd. (https://ecosoft.co.th)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from odoo.tools import SQL

from odoo.addons.queue_job.job import ENQUEUED, PENDING, STARTED, WAIT_DEPENDENCIES

#: queue.job states that are not terminal yet (done / cancelled / failed).
RUNNING_STATES = (WAIT_DEPENDENCIES, PENDING, ENQUEUED, STARTED)

RUNNING_RECORD_IDS_INDEX = "queue_job_running_record_ids_gin_idx"

# JobSerialized values created on 18.0 are JSON strings in a jsonb column, while
# migrated values can be JSON objects. Normalize both storage shapes before
# extracting the record ids.
JOB_RECORD_IDS_SQL = SQL(
"COALESCE(records -> 'ids', ((records #>> '{}')::jsonb) -> 'ids')"
)
31 changes: 31 additions & 0 deletions queue_job_is_running/models/queue_job.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2026 Ecosoft Co., Ltd. (https://ecosoft.co.th)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from odoo import models
from odoo.tools import SQL, index_exists

from .constants import JOB_RECORD_IDS_SQL, RUNNING_RECORD_IDS_INDEX


class QueueJob(models.Model):
_inherit = "queue.job"

def init(self):
result = super().init()
if not index_exists(self._cr, RUNNING_RECORD_IDS_INDEX):
self._cr.execute(
SQL(
"""
CREATE INDEX %s
ON %s
USING gin ((%s) jsonb_path_ops)
WHERE state IN (
'wait_dependencies', 'pending', 'enqueued', 'started'
)
""",
SQL.identifier(RUNNING_RECORD_IDS_INDEX),
SQL.identifier(self._table),
JOB_RECORD_IDS_SQL,
)
)
return result
70 changes: 70 additions & 0 deletions queue_job_is_running/models/queue_job_status_mixin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Copyright 2026 Ecosoft Co., Ltd. (https://ecosoft.co.th)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from lxml import etree

from odoo import api, fields, models
from odoo.tools import SQL

from .constants import JOB_RECORD_IDS_SQL, RUNNING_STATES


class QueueJobStatusMixin(models.AbstractModel):
_name = "queue.job.status.mixin"
_description = "Queue Job Status Mixin"

running_job_names = fields.Char(compute="_compute_running_job_names")

def _compute_running_job_names(self):
"""List the non-terminal queue jobs targeting each record."""
self.running_job_names = False
target_ids = self.ids
if not target_ids:
return

queue_job = self.env["queue.job"].sudo()
# Raw SQL does not trigger the ORM's automatic field flush.
queue_job.flush_model(
["model_name", "state", "records", "name", "func_string", "method_name"]
)
self.env.cr.execute(
SQL(
"""
SELECT target.id,
string_agg(
DISTINCT COALESCE(
job.name, job.func_string, job.method_name
),
', '
ORDER BY COALESCE(
job.name, job.func_string, job.method_name
)
)
FROM unnest(%s::integer[]) AS target(id)
JOIN %s AS job
ON %s @> jsonb_build_array(target.id)
WHERE job.model_name = %s
AND job.state = ANY(%s)
GROUP BY target.id
""",
target_ids,
SQL.identifier(queue_job._table),
JOB_RECORD_IDS_SQL,
self._name,
list(RUNNING_STATES),
)
)
names_by_record_id = dict(self.env.cr.fetchall())
for record in self:
record.running_job_names = names_by_record_id.get(record.id, False)

@api.model
def _get_view(self, view_id=None, view_type="form", **options):
arch, view = super()._get_view(view_id=view_id, view_type=view_type, **options)
if view_type == "form":
for sheet in arch.xpath("/form/sheet"):
label = self.env["ir.qweb"]._render(
"queue_job_is_running.running_job_banner", {}
)
sheet.addprevious(etree.fromstring(label))
return arch, view
3 changes: 3 additions & 0 deletions queue_job_is_running/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
1 change: 1 addition & 0 deletions queue_job_is_running/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Saran Lim. \<<saranl@ecosoft.co.th>\>
6 changes: 6 additions & 0 deletions queue_job_is_running/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This addon provides the `queue.job.status.mixin` mixin. It displays a warning banner on
a form view when the record has one or more non-terminal queue jobs and lists their
names.

The status is read directly from `queue.job`, so no method is required to mark a job as
running or finished.
18 changes: 18 additions & 0 deletions queue_job_is_running/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Inherit `queue.job.status.mixin` and enqueue the job normally:

```python
class MyModel(models.Model):
_name = "my.model"
_inherit = ["queue.job.status.mixin"]

def action_process(self):
self.with_delay(
description="Process document",
)._process_in_background()
```

Set `description` to display a user-friendly job name. If it is omitted, the technical
name generated by `queue_job` is displayed instead.

The banner is visible while the job is pending, enqueued, started, or waiting for
dependencies. It disappears automatically when the job is done, failed, or cancelled.
Loading