diff --git a/README.md b/README.md
index aeafe8e05c..f824faf82c 100644
--- a/README.md
+++ b/README.md
@@ -24,7 +24,7 @@ addon | version | maintainers | summary
--- | --- | --- | ---
[base_export_async](base_export_async/) | 16.0.1.2.0 | | Asynchronous export with job queue
[base_import_async](base_import_async/) | 16.0.1.2.1 | | Import CSV files in the background
-[queue_job](queue_job/) | 16.0.2.13.2 |
| Job Queue
+[queue_job](queue_job/) | 16.0.3.0.0 |
| Job Queue
[queue_job_batch](queue_job_batch/) | 16.0.1.0.1 | | Job Queue Batch
[queue_job_cron](queue_job_cron/) | 16.0.2.1.0 | | Scheduled Actions as Queue Jobs
[queue_job_cron_jobrunner](queue_job_cron_jobrunner/) | 16.0.1.1.0 |
| Run jobs without a dedicated JobRunner
diff --git a/queue_job/README.rst b/queue_job/README.rst
index 1adbad629f..40c4be48c2 100644
--- a/queue_job/README.rst
+++ b/queue_job/README.rst
@@ -11,7 +11,7 @@ Job Queue
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- !! source digest: sha256:2bd5c794474dd35dcd9b22179fa7d2690e791192862beaeeb674d8bedbb77558
+ !! source digest: sha256:66ce31b496162c3eb2d775db0c116656cb3e4b67569e4c92e2eb99add0b19a48
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Mature-brightgreen.png
diff --git a/queue_job/__manifest__.py b/queue_job/__manifest__.py
index 158c54b1de..72d0a71cac 100644
--- a/queue_job/__manifest__.py
+++ b/queue_job/__manifest__.py
@@ -2,7 +2,7 @@
{
"name": "Job Queue",
- "version": "16.0.2.13.2",
+ "version": "16.0.3.0.0",
"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 e3dbd5309c..02e05a6a96 100644
--- a/queue_job/controllers/main.py
+++ b/queue_job/controllers/main.py
@@ -13,8 +13,9 @@
from psycopg2 import OperationalError, errorcodes
from werkzeug.exceptions import BadRequest, Forbidden
-from odoo import SUPERUSER_ID, _, api, http, registry, tools
+from odoo import SUPERUSER_ID, _, api, http, tools
from odoo.service.model import PG_CONCURRENCY_ERRORS_TO_RETRY
+from odoo.tools import config
from ..delay import chain, group
from ..exception import FailedJobError, NothingToDoJob, RetryableJobError
@@ -38,8 +39,10 @@ def _prevent_commit(cr):
def forbidden_commit(*args, **kwargs):
raise RuntimeError(
"Commit is forbidden in queue jobs. "
- "If the current job is a cron running as queue job, "
- "modify it to run as a normal cron."
+ 'You may want to enable the "Allow Commit" option on the Job '
+ "Function. Alternatively, if the current job is a cron running as "
+ "queue job, you can modify it to run as a normal cron. More details on: "
+ "https://github.com/OCA/queue/wiki/Upgrade-warning:-commits-inside-jobs"
)
original_commit = cr.commit
@@ -103,7 +106,8 @@ def _try_perform_job(cls, env, job):
job.set_done()
job.store()
env.flush_all()
- env.cr.commit()
+ if not config["test_enable"]:
+ env.cr.commit()
_logger.debug("%s done", job)
@classmethod
@@ -141,8 +145,7 @@ def _enqueue_dependent_jobs(cls, env, job):
def _runjob(cls, env: api.Environment, job: Job) -> None:
def retry_postpone(job, message, seconds=None):
job.env.clear()
- with registry(job.env.cr.dbname).cursor() as new_cr:
- job.env = api.Environment(new_cr, SUPERUSER_ID, {})
+ with job.in_temporary_env():
job.postpone(result=message, seconds=seconds)
job.set_pending(reset_retry=False)
job.store()
@@ -178,6 +181,7 @@ def retry_postpone(job, message, seconds=None):
# traceback in the logs we should have the traceback when all
# retries are exhausted
env.cr.rollback()
+ return
except (FailedJobError, Exception) as orig_exception:
buff = StringIO()
@@ -185,8 +189,7 @@ def retry_postpone(job, message, seconds=None):
traceback_txt = buff.getvalue()
_logger.error(traceback_txt)
job.env.clear()
- with registry(job.env.cr.dbname).cursor() as new_cr:
- job.env = job.env(cr=new_cr)
+ with job.in_temporary_env():
vals = cls._get_failure_values(job, traceback_txt, orig_exception)
job.set_failed(**vals)
job.store()
@@ -240,6 +243,7 @@ def create_test_job(
failure_rate=0,
job_duration=0,
commit_within_job=False,
+ failure_retry_seconds=0,
):
"""Create test jobs
@@ -287,6 +291,12 @@ def create_test_job(
except ValueError:
max_retries = None
+ if failure_retry_seconds is not None:
+ try:
+ failure_retry_seconds = int(failure_retry_seconds)
+ except ValueError:
+ failure_retry_seconds = 0
+
if size == 1:
return self._create_single_test_job(
priority=priority,
@@ -296,6 +306,7 @@ def create_test_job(
failure_rate=failure_rate,
job_duration=job_duration,
commit_within_job=commit_within_job,
+ failure_retry_seconds=failure_retry_seconds,
)
if size > 1:
@@ -308,6 +319,7 @@ def create_test_job(
failure_rate=failure_rate,
job_duration=job_duration,
commit_within_job=commit_within_job,
+ failure_retry_seconds=failure_retry_seconds,
)
return ""
@@ -321,6 +333,7 @@ def _create_single_test_job(
failure_rate=0,
job_duration=0,
commit_within_job=False,
+ failure_retry_seconds=0,
):
delayed = (
http.request.env["queue.job"]
@@ -334,6 +347,7 @@ def _create_single_test_job(
failure_rate=failure_rate,
job_duration=job_duration,
commit_within_job=commit_within_job,
+ failure_retry_seconds=failure_retry_seconds,
)
)
return "job uuid: %s" % (delayed.db_record().uuid,)
@@ -350,6 +364,7 @@ def _create_graph_test_jobs(
failure_rate=0,
job_duration=0,
commit_within_job=False,
+ failure_retry_seconds=0,
):
model = http.request.env["queue.job"]
current_count = 0
@@ -376,6 +391,7 @@ def _create_graph_test_jobs(
failure_rate=failure_rate,
job_duration=job_duration,
commit_within_job=commit_within_job,
+ failure_retry_seconds=failure_retry_seconds,
)
)
diff --git a/queue_job/i18n/ca.po b/queue_job/i18n/ca.po
index 1a4ae1c1f5..4ad181bf58 100644
--- a/queue_job/i18n/ca.po
+++ b/queue_job/i18n/ca.po
@@ -59,6 +59,19 @@ msgstr "Estat de l'activitat"
msgid "Activity Type Icon"
msgstr "Icona del tipus d'activitat"
+#. module: queue_job
+#: model:ir.model.fields,field_description:queue_job.field_queue_job_function__allow_commit
+msgid "Allow Commit"
+msgstr ""
+
+#. module: queue_job
+#: model:ir.model.fields,help:queue_job.field_queue_job_function__allow_commit
+msgid ""
+"Allows the job to commit transactions during execution. Under the hood, this "
+"executes the job in a new database cursor, which incurs an overhead as it "
+"requires an extra connection to the database. "
+msgstr ""
+
#. module: queue_job
#: model:ir.model.fields,field_description:queue_job.field_queue_job__args
msgid "Args"
@@ -927,8 +940,8 @@ msgstr "UUID"
msgid ""
"Unexpected format of Related Action for {}.\n"
"Example of valid format:\n"
-"{{\"enable\": True, \"func_name\": \"related_action_foo\", "
-"\"kwargs\" {{\"limit\": 10}}}}"
+"{{\"enable\": True, \"func_name\": \"related_action_foo\", \"kwargs\" "
+"{{\"limit\": 10}}}}"
msgstr ""
#. module: queue_job
diff --git a/queue_job/i18n/de.po b/queue_job/i18n/de.po
index 41d291bb57..012cf8b950 100644
--- a/queue_job/i18n/de.po
+++ b/queue_job/i18n/de.po
@@ -60,6 +60,19 @@ msgstr "Aktivitätsstatus"
msgid "Activity Type Icon"
msgstr "Icon für Aktivitätstyp"
+#. module: queue_job
+#: model:ir.model.fields,field_description:queue_job.field_queue_job_function__allow_commit
+msgid "Allow Commit"
+msgstr ""
+
+#. module: queue_job
+#: model:ir.model.fields,help:queue_job.field_queue_job_function__allow_commit
+msgid ""
+"Allows the job to commit transactions during execution. Under the hood, this "
+"executes the job in a new database cursor, which incurs an overhead as it "
+"requires an extra connection to the database. "
+msgstr ""
+
#. module: queue_job
#: model:ir.model.fields,field_description:queue_job.field_queue_job__args
msgid "Args"
@@ -952,13 +965,13 @@ msgstr "UUID"
msgid ""
"Unexpected format of Related Action for {}.\n"
"Example of valid format:\n"
-"{{\"enable\": True, \"func_name\": \"related_action_foo\", "
-"\"kwargs\" {{\"limit\": 10}}}}"
+"{{\"enable\": True, \"func_name\": \"related_action_foo\", \"kwargs\" "
+"{{\"limit\": 10}}}}"
msgstr ""
"Unerwartetes Format der zugehörigen Aktion für {}.\n"
"Beispiel für ein gültiges Format:\n"
-"{{\"enable\": True, \"func_name\": \"related_action_foo\", "
-"\"kwargs\" {{\"limit\": 10}}}}"
+"{{\"enable\": True, \"func_name\": \"related_action_foo\", \"kwargs\" "
+"{{\"limit\": 10}}}}"
#. module: queue_job
#. odoo-python
diff --git a/queue_job/i18n/es.po b/queue_job/i18n/es.po
index 0580170ec6..fe2f2fb8ff 100644
--- a/queue_job/i18n/es.po
+++ b/queue_job/i18n/es.po
@@ -59,6 +59,19 @@ msgstr "Estado de la actividad"
msgid "Activity Type Icon"
msgstr "Icono de tipo de actividad"
+#. module: queue_job
+#: model:ir.model.fields,field_description:queue_job.field_queue_job_function__allow_commit
+msgid "Allow Commit"
+msgstr ""
+
+#. module: queue_job
+#: model:ir.model.fields,help:queue_job.field_queue_job_function__allow_commit
+msgid ""
+"Allows the job to commit transactions during execution. Under the hood, this "
+"executes the job in a new database cursor, which incurs an overhead as it "
+"requires an extra connection to the database. "
+msgstr ""
+
#. module: queue_job
#: model:ir.model.fields,field_description:queue_job.field_queue_job__args
msgid "Args"
@@ -946,13 +959,13 @@ msgstr "UUID"
msgid ""
"Unexpected format of Related Action for {}.\n"
"Example of valid format:\n"
-"{{\"enable\": True, \"func_name\": \"related_action_foo\", "
-"\"kwargs\" {{\"limit\": 10}}}}"
+"{{\"enable\": True, \"func_name\": \"related_action_foo\", \"kwargs\" "
+"{{\"limit\": 10}}}}"
msgstr ""
"Formato inesperado en la acción relacionada con {}.\n"
"Ejemplo de un formato válido:\n"
-"{{\"enable\": True, \"func_name\": \"related_action_foo\", "
-"\"kwargs\" {{\"limit\": 10}}}}"
+"{{\"enable\": True, \"func_name\": \"related_action_foo\", \"kwargs\" "
+"{{\"limit\": 10}}}}"
#. module: queue_job
#. odoo-python
diff --git a/queue_job/i18n/fr.po b/queue_job/i18n/fr.po
index 0a03d545ef..095c69aae6 100644
--- a/queue_job/i18n/fr.po
+++ b/queue_job/i18n/fr.po
@@ -59,6 +59,19 @@ msgstr "Statut de l’activité"
msgid "Activity Type Icon"
msgstr "Icône de type d’activité"
+#. module: queue_job
+#: model:ir.model.fields,field_description:queue_job.field_queue_job_function__allow_commit
+msgid "Allow Commit"
+msgstr ""
+
+#. module: queue_job
+#: model:ir.model.fields,help:queue_job.field_queue_job_function__allow_commit
+msgid ""
+"Allows the job to commit transactions during execution. Under the hood, this "
+"executes the job in a new database cursor, which incurs an overhead as it "
+"requires an extra connection to the database. "
+msgstr ""
+
#. module: queue_job
#: model:ir.model.fields,field_description:queue_job.field_queue_job__args
msgid "Args"
@@ -946,13 +959,13 @@ msgstr "UUID"
msgid ""
"Unexpected format of Related Action for {}.\n"
"Example of valid format:\n"
-"{{\"enable\": True, \"func_name\": \"related_action_foo\", "
-"\"kwargs\" {{\"limit\": 10}}}}"
+"{{\"enable\": True, \"func_name\": \"related_action_foo\", \"kwargs\" "
+"{{\"limit\": 10}}}}"
msgstr ""
"Format inattendu pour l’action rattachée de {}.\n"
"Exemple de format valide :\n"
-"{{\"enable\": True, \"func_name\": \"related_action_foo\", "
-"\"kwargs\" {{\"limit\": 10}}}}"
+"{{\"enable\": True, \"func_name\": \"related_action_foo\", \"kwargs\" "
+"{{\"limit\": 10}}}}"
#. module: queue_job
#. odoo-python
diff --git a/queue_job/i18n/it.po b/queue_job/i18n/it.po
index 5baf58076e..0a45b4f71f 100644
--- a/queue_job/i18n/it.po
+++ b/queue_job/i18n/it.po
@@ -59,6 +59,19 @@ msgstr "Stato attività"
msgid "Activity Type Icon"
msgstr "Icona tipo attività"
+#. module: queue_job
+#: model:ir.model.fields,field_description:queue_job.field_queue_job_function__allow_commit
+msgid "Allow Commit"
+msgstr ""
+
+#. module: queue_job
+#: model:ir.model.fields,help:queue_job.field_queue_job_function__allow_commit
+msgid ""
+"Allows the job to commit transactions during execution. Under the hood, this "
+"executes the job in a new database cursor, which incurs an overhead as it "
+"requires an extra connection to the database. "
+msgstr ""
+
#. module: queue_job
#: model:ir.model.fields,field_description:queue_job.field_queue_job__args
msgid "Args"
@@ -943,13 +956,13 @@ msgstr "UUID"
msgid ""
"Unexpected format of Related Action for {}.\n"
"Example of valid format:\n"
-"{{\"enable\": True, \"func_name\": \"related_action_foo\", "
-"\"kwargs\" {{\"limit\": 10}}}}"
+"{{\"enable\": True, \"func_name\": \"related_action_foo\", \"kwargs\" "
+"{{\"limit\": 10}}}}"
msgstr ""
"Formato inaspettato di azione colegata per {}.\n"
"Esempio di formato valido:\n"
-"{{\"enable\": True, \"func_name\": \"related_action_foo\", "
-"\"kwargs\" {{\"limit\": 10}}}}"
+"{{\"enable\": True, \"func_name\": \"related_action_foo\", \"kwargs\" "
+"{{\"limit\": 10}}}}"
#. module: queue_job
#. odoo-python
diff --git a/queue_job/i18n/queue_job.pot b/queue_job/i18n/queue_job.pot
index 3a3462af74..9c2a8985bc 100644
--- a/queue_job/i18n/queue_job.pot
+++ b/queue_job/i18n/queue_job.pot
@@ -52,6 +52,19 @@ msgstr ""
msgid "Activity Type Icon"
msgstr ""
+#. module: queue_job
+#: model:ir.model.fields,field_description:queue_job.field_queue_job_function__allow_commit
+msgid "Allow Commit"
+msgstr ""
+
+#. module: queue_job
+#: model:ir.model.fields,help:queue_job.field_queue_job_function__allow_commit
+msgid ""
+"Allows the job to commit transactions during execution. Under the hood, this"
+" executes the job in a new database cursor, which incurs an overhead as it "
+"requires an extra connection to the database. "
+msgstr ""
+
#. module: queue_job
#: model:ir.model.fields,field_description:queue_job.field_queue_job__args
msgid "Args"
diff --git a/queue_job/i18n/tr.po b/queue_job/i18n/tr.po
index c020117adf..f132fea560 100644
--- a/queue_job/i18n/tr.po
+++ b/queue_job/i18n/tr.po
@@ -59,6 +59,19 @@ msgstr "Aktivite Durumu"
msgid "Activity Type Icon"
msgstr "Aktivite Türü Simgesi"
+#. module: queue_job
+#: model:ir.model.fields,field_description:queue_job.field_queue_job_function__allow_commit
+msgid "Allow Commit"
+msgstr ""
+
+#. module: queue_job
+#: model:ir.model.fields,help:queue_job.field_queue_job_function__allow_commit
+msgid ""
+"Allows the job to commit transactions during execution. Under the hood, this "
+"executes the job in a new database cursor, which incurs an overhead as it "
+"requires an extra connection to the database. "
+msgstr ""
+
#. module: queue_job
#: model:ir.model.fields,field_description:queue_job.field_queue_job__args
msgid "Args"
@@ -943,13 +956,13 @@ msgstr "UUID"
msgid ""
"Unexpected format of Related Action for {}.\n"
"Example of valid format:\n"
-"{{\"enable\": True, \"func_name\": \"related_action_foo\", "
-"\"kwargs\" {{\"limit\": 10}}}}"
+"{{\"enable\": True, \"func_name\": \"related_action_foo\", \"kwargs\" "
+"{{\"limit\": 10}}}}"
msgstr ""
"İlgili eylem için beklenmeyen biçim {}.\n"
"Doğru biçim örneği:\n"
-"{{\"enable\": True, \"func_name\": \"related_action_foo\", "
-"\"kwargs\" {{\"limit\": 10}}}}"
+"{{\"enable\": True, \"func_name\": \"related_action_foo\", \"kwargs\" "
+"{{\"limit\": 10}}}}"
#. module: queue_job
#. odoo-python
diff --git a/queue_job/i18n/zh_CN.po b/queue_job/i18n/zh_CN.po
index f75cca8176..aeedd0d03a 100644
--- a/queue_job/i18n/zh_CN.po
+++ b/queue_job/i18n/zh_CN.po
@@ -56,6 +56,19 @@ msgstr "活动状态"
msgid "Activity Type Icon"
msgstr ""
+#. module: queue_job
+#: model:ir.model.fields,field_description:queue_job.field_queue_job_function__allow_commit
+msgid "Allow Commit"
+msgstr ""
+
+#. module: queue_job
+#: model:ir.model.fields,help:queue_job.field_queue_job_function__allow_commit
+msgid ""
+"Allows the job to commit transactions during execution. Under the hood, this "
+"executes the job in a new database cursor, which incurs an overhead as it "
+"requires an extra connection to the database. "
+msgstr ""
+
#. module: queue_job
#: model:ir.model.fields,field_description:queue_job.field_queue_job__args
msgid "Args"
@@ -929,8 +942,8 @@ msgstr "UUID"
msgid ""
"Unexpected format of Related Action for {}.\n"
"Example of valid format:\n"
-"{{\"enable\": True, \"func_name\": \"related_action_foo\", "
-"\"kwargs\" {{\"limit\": 10}}}}"
+"{{\"enable\": True, \"func_name\": \"related_action_foo\", \"kwargs\" "
+"{{\"limit\": 10}}}}"
msgstr ""
#. module: queue_job
diff --git a/queue_job/job.py b/queue_job/job.py
index 86407be3bb..b2d64c6d34 100644
--- a/queue_job/job.py
+++ b/queue_job/job.py
@@ -8,6 +8,7 @@
import sys
import uuid
import weakref
+from contextlib import contextmanager, nullcontext
from datetime import datetime, timedelta
from random import randint
@@ -423,14 +424,9 @@ def __init__(
raise TypeError("Job accepts only methods of Models")
recordset = func.__self__
- env = recordset.env
self.method_name = func.__name__
self.recordset = recordset
- self.env = env
- self.job_model = self.env["queue.job"]
- self.job_model_name = "queue.job"
-
self.job_config = (
self.env["queue.job.function"].sudo().job_config(self.job_function_name)
)
@@ -480,10 +476,10 @@ def __init__(
self.exc_message = None
self.exc_info = None
- if "company_id" in env.context:
- company_id = env.context["company_id"]
+ if "company_id" in self.env.context:
+ company_id = self.env.context["company_id"]
else:
- company_id = env.company.id
+ company_id = self.env.company.id
self.company_id = company_id
self._eta = None
self.eta = eta
@@ -508,7 +504,12 @@ def perform(self):
"""
self.retry += 1
try:
- self.result = self.func(*tuple(self.args), **self.kwargs)
+ if self.job_config.allow_commit:
+ env_context_manager = self.in_temporary_env()
+ else:
+ env_context_manager = nullcontext()
+ with env_context_manager:
+ self.result = self.func(*tuple(self.args), **self.kwargs)
except RetryableJobError as err:
if err.ignore_retry:
self.retry -= 1
@@ -528,6 +529,16 @@ def perform(self):
return self.result
+ @contextmanager
+ def in_temporary_env(self):
+ with self.env.registry.cursor() as new_cr:
+ env = self.env
+ self._env = env(cr=new_cr)
+ try:
+ yield
+ finally:
+ self._env = env
+
def _get_common_dependent_jobs_query(self):
return """
UPDATE queue_job
@@ -686,6 +697,14 @@ def __hash__(self):
def db_record(self):
return self.db_records_from_uuids(self.env, [self.uuid])
+ @property
+ def env(self):
+ return self.recordset.env
+
+ @env.setter
+ def _env(self, env):
+ self.recordset = self.recordset.with_env(env)
+
@property
def func(self):
recordset = self.recordset.with_context(job_uuid=self.uuid)
@@ -750,7 +769,7 @@ def model_name(self):
@property
def user_id(self):
- return self.recordset.env.uid
+ return self.env.uid
@property
def eta(self):
diff --git a/queue_job/models/queue_job.py b/queue_job/models/queue_job.py
index f8c117fa2d..fd451818a7 100644
--- a/queue_job/models/queue_job.py
+++ b/queue_job/models/queue_job.py
@@ -12,7 +12,7 @@
from odoo.addons.base_sparse_field.models.fields import Serialized
from ..delay import Graph
-from ..exception import JobError
+from ..exception import JobError, RetryableJobError
from ..fields import JobSerialized
from ..job import (
CANCELLED,
@@ -459,10 +459,23 @@ def related_action_open_record(self):
)
return action
- def _test_job(self, failure_rate=0, job_duration=0, commit_within_job=False):
+ def _test_job(
+ self,
+ failure_rate=0,
+ job_duration=0,
+ commit_within_job=False,
+ failure_retry_seconds=0,
+ ):
_logger.info("Running test job.")
if random.random() <= failure_rate:
- raise JobError("Job failed")
+ if failure_retry_seconds:
+ raise RetryableJobError(
+ f"Retryable job failed, will be retried in "
+ f"{failure_retry_seconds} seconds",
+ seconds=failure_retry_seconds,
+ )
+ else:
+ raise JobError("Job failed")
if job_duration:
time.sleep(job_duration)
if commit_within_job:
diff --git a/queue_job/models/queue_job_function.py b/queue_job/models/queue_job_function.py
index ad034b46bc..0fcd4fe269 100644
--- a/queue_job/models/queue_job_function.py
+++ b/queue_job/models/queue_job_function.py
@@ -28,7 +28,8 @@ class QueueJobFunction(models.Model):
"related_action_enable "
"related_action_func_name "
"related_action_kwargs "
- "job_function_id ",
+ "job_function_id "
+ "allow_commit",
)
def _default_channel(self):
@@ -79,6 +80,12 @@ def _default_channel(self):
"enable, func_name, kwargs.\n"
"See the module description for details.",
)
+ allow_commit = fields.Boolean(
+ help="Allows the job to commit transactions during execution. "
+ "Under the hood, this executes the job in a new database cursor, "
+ "which incurs an overhead as it requires an extra connection to "
+ "the database. "
+ )
@api.depends("model_id.model", "method")
def _compute_name(self):
@@ -149,6 +156,7 @@ def job_default_config(self):
related_action_func_name=None,
related_action_kwargs={},
job_function_id=None,
+ allow_commit=False,
)
def _parse_retry_pattern(self):
@@ -184,6 +192,7 @@ def job_config(self, name):
related_action_func_name=config.related_action.get("func_name"),
related_action_kwargs=config.related_action.get("kwargs", {}),
job_function_id=config.id,
+ allow_commit=config.allow_commit,
)
def _retry_pattern_format_error_message(self):
diff --git a/queue_job/static/description/index.html b/queue_job/static/description/index.html
index bc065039fc..b4d6af8afe 100644
--- a/queue_job/static/description/index.html
+++ b/queue_job/static/description/index.html
@@ -372,7 +372,7 @@
This addon adds an integrated Job Queue to Odoo.
diff --git a/queue_job/tests/common.py b/queue_job/tests/common.py index 33173e3f2b..67db90b5c2 100644 --- a/queue_job/tests/common.py +++ b/queue_job/tests/common.py @@ -276,7 +276,7 @@ def _add_job(self, *args, **kwargs): def _prepare_context(self, job): # pylint: disable=context-overridden - job_model = job.job_model.with_context({}) + job_model = job.env["queue.job"].with_context({}) field_records = job_model._fields["records"] # Filter the context to simulate store/load of the job job.recordset = field_records.convert_to_write(job.recordset, job_model) diff --git a/queue_job/tests/test_model_job_function.py b/queue_job/tests/test_model_job_function.py index 84676fdb65..9095f2a55e 100644 --- a/queue_job/tests/test_model_job_function.py +++ b/queue_job/tests/test_model_job_function.py @@ -42,6 +42,7 @@ def test_function_job_config(self): ' "func_name": "related_action_foo",' ' "kwargs": {"b": 1}}' ), + "allow_commit": True, } ) self.assertEqual( @@ -53,5 +54,6 @@ def test_function_job_config(self): related_action_func_name="related_action_foo", related_action_kwargs={"b": 1}, job_function_id=job_function.id, + allow_commit=True, ), ) diff --git a/queue_job/tests/test_run_rob_controller.py b/queue_job/tests/test_run_rob_controller.py index bb63bc82ec..1a15f4363a 100644 --- a/queue_job/tests/test_run_rob_controller.py +++ b/queue_job/tests/test_run_rob_controller.py @@ -15,3 +15,9 @@ def test_get_failure_values(self): self.assertEqual( rslt, {"exc_info": "info", "exc_name": "Exception", "exc_message": "zero"} ) + + def test_runjob_success(self): + job = self.env["queue.job"].with_delay()._test_job() + RunJobController._runjob(self.env, job) + self.assertEqual(job.state, "done") + self.assertEqual(job.db_record().state, "done") diff --git a/queue_job/views/queue_job_function_views.xml b/queue_job/views/queue_job_function_views.xml index a6e2ce402c..6c208b2b67 100644 --- a/queue_job/views/queue_job_function_views.xml +++ b/queue_job/views/queue_job_function_views.xml @@ -11,6 +11,7 @@