diff --git a/.oca/oca-port/blacklist/queue_job.json b/.oca/oca-port/blacklist/queue_job.json index 2cf4dd06eb..a208b8dcc4 100644 --- a/.oca/oca-port/blacklist/queue_job.json +++ b/.oca/oca-port/blacklist/queue_job.json @@ -6,6 +6,9 @@ "466": "Reverts https://github.com/OCA/queue/pull/387", "511": "Icon already updated for v15", "443": "Squashed w/ 453, commit rewritten", - "453": "Squashed w/ 443, commit rewritten" + "453": "Squashed w/ 443, commit rewritten", + "403": "Lint fixes, relevant code already ported", + "537": "Already ported", + "571": "Already ported" } } diff --git a/queue_job/__manifest__.py b/queue_job/__manifest__.py index 97cc820956..8fea895a4c 100644 --- a/queue_job/__manifest__.py +++ b/queue_job/__manifest__.py @@ -2,7 +2,7 @@ { "name": "Job Queue", - "version": "15.0.2.3.5", + "version": "15.0.2.3.6", "author": "Camptocamp,ACSONE SA/NV,Odoo Community Association (OCA)", "website": "https://github.com/OCA/queue", "license": "LGPL-3", diff --git a/queue_job/controllers/main.py b/queue_job/controllers/main.py index da42b53e99..f83aa9b54f 100644 --- a/queue_job/controllers/main.py +++ b/queue_job/controllers/main.py @@ -175,6 +175,16 @@ def create_test_job( size=1, failure_rate=0, ): + """Create test jobs + + Examples of urls: + + * http://127.0.0.1:8069/queue_job/create_test_job: single job + * http://127.0.0.1:8069/queue_job/create_test_job?size=10: a graph of 10 jobs + * http://127.0.0.1:8069/queue_job/create_test_job?size=10&failure_rate=0.5: + a graph of 10 jobs, half will fail + + """ if not http.request.env.user.has_group("base.group_erp_manager"): raise Forbidden(_("Access Denied")) diff --git a/queue_job/job.py b/queue_job/job.py index 1a61881e30..d38a899095 100644 --- a/queue_job/job.py +++ b/queue_job/job.py @@ -89,14 +89,19 @@ def identity_example(job_): Usually you will probably always want to include at least the name of the model and method. """ + hasher = identity_exact_hasher(job_) + return hasher.hexdigest() + + +def identity_exact_hasher(job_): + """Prepare hasher object for identity_exact.""" hasher = hashlib.sha1() hasher.update(job_.model_name.encode("utf-8")) hasher.update(job_.method_name.encode("utf-8")) hasher.update(str(sorted(job_.recordset.ids)).encode("utf-8")) hasher.update(str(job_.args).encode("utf-8")) hasher.update(str(sorted(job_.kwargs.items())).encode("utf-8")) - - return hasher.hexdigest() + return hasher @total_ordering diff --git a/queue_job/migrations/15.0.2.3.6/pre-migration.py b/queue_job/migrations/15.0.2.3.6/pre-migration.py new file mode 100644 index 0000000000..53d9690caa --- /dev/null +++ b/queue_job/migrations/15.0.2.3.6/pre-migration.py @@ -0,0 +1,10 @@ +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html) + +from odoo.tools.sql import table_exists + + +def migrate(cr, version): + if table_exists(cr, "queue_job"): + # Drop index 'queue_job_identity_key_state_partial_index', + # it will be recreated during the update + cr.execute("DROP INDEX IF EXISTS queue_job_identity_key_state_partial_index;") diff --git a/queue_job/models/queue_job.py b/queue_job/models/queue_job.py index 7eb1620cfb..0f0b866273 100644 --- a/queue_job/models/queue_job.py +++ b/queue_job/models/queue_job.py @@ -139,7 +139,7 @@ def init(self): self._cr.execute( "CREATE INDEX queue_job_identity_key_state_partial_index " "ON queue_job (identity_key) WHERE state in ('pending', " - "'enqueued') AND identity_key IS NOT NULL;" + "'enqueued', 'wait_dependencies') AND identity_key IS NOT NULL;" ) @api.depends("records") diff --git a/queue_job/readme/USAGE.rst b/queue_job/readme/USAGE.rst index 743da10236..8f7da0473c 100644 --- a/queue_job/readme/USAGE.rst +++ b/queue_job/readme/USAGE.rst @@ -318,6 +318,12 @@ tests), and it makes tests smaller. The best way to run such assertions on the enqueued jobs is to use ``odoo.addons.queue_job.tests.common.trap_jobs()``. +Inside this context manager, instead of being added in the database's queue, +jobs are pushed in an in-memory list. The context manager then provides useful +helpers to verify that jobs have been enqueued with the expected arguments. It +even can run the jobs of its list synchronously! Details in +``odoo.addons.queue_job.tests.common.JobsTester``. + A very small example (more details in ``tests/common.py``): .. code-block:: python diff --git a/queue_job/views/queue_job_views.xml b/queue_job/views/queue_job_views.xml index d58739a82e..51336f5197 100644 --- a/queue_job/views/queue_job_views.xml +++ b/queue_job/views/queue_job_views.xml @@ -244,6 +244,11 @@ string="Failed" domain="[('state', '=', 'failed')]" /> +