diff --git a/.oca/oca-port/blacklist/queue_job.json b/.oca/oca-port/blacklist/queue_job.json index d6eda921fb..2cf4dd06eb 100644 --- a/.oca/oca-port/blacklist/queue_job.json +++ b/.oca/oca-port/blacklist/queue_job.json @@ -3,6 +3,9 @@ "387": "Reverted later by https://github.com/OCA/queue/pull/466", "413": "No reason to port repo template sync", "440": "Already ported", - "466": "Reverts https://github.com/OCA/queue/pull/387" + "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" } } diff --git a/queue_job/__manifest__.py b/queue_job/__manifest__.py index 1d0a25508f..5ec9d5673f 100644 --- a/queue_job/__manifest__.py +++ b/queue_job/__manifest__.py @@ -7,7 +7,7 @@ "website": "https://github.com/OCA/queue", "license": "LGPL-3", "category": "Generic Modules", - "depends": ["mail"], + "depends": ["mail", "base_sparse_field"], "external_dependencies": {"python": ["requests"]}, "data": [ "security/security.xml", diff --git a/queue_job/controllers/main.py b/queue_job/controllers/main.py index 555fd3de65..da42b53e99 100644 --- a/queue_job/controllers/main.py +++ b/queue_job/controllers/main.py @@ -130,6 +130,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() diff --git a/queue_job/fields.py b/queue_job/fields.py index 7a4bcaa6b9..2c78c18836 100644 --- a/queue_job/fields.py +++ b/queue_job/fields.py @@ -69,6 +69,9 @@ def convert_to_record(self, value, record): class JobEncoder(json.JSONEncoder): """Encode Odoo recordsets so that we can later recompose them""" + def _get_record_context(self, obj): + return obj._job_prepare_context_before_enqueue() + def default(self, obj): if isinstance(obj, models.BaseModel): return { @@ -77,6 +80,7 @@ def default(self, obj): "ids": obj.ids, "uid": obj.env.uid, "su": obj.env.su, + "context": self._get_record_context(obj), } elif isinstance(obj, datetime): return {"_type": "datetime_isoformat", "value": obj.isoformat()} diff --git a/queue_job/jobrunner/runner.py b/queue_job/jobrunner/runner.py index 8dbe39d97c..fb6e60e5be 100644 --- a/queue_job/jobrunner/runner.py +++ b/queue_job/jobrunner/runner.py @@ -35,6 +35,10 @@ or ``False`` if unset. - ``ODOO_QUEUE_JOB_JOBRUNNER_DB_PORT=5432``, default ``db_port`` or ``False`` if unset. + - ``ODOO_QUEUE_JOB_JOBRUNNER_DB_USER=userdb``, default ``db_user`` + or ``False`` if unset. + - ``ODOO_QUEUE_JOB_JOBRUNNER_DB_PASSWORD=passdb``, default ``db_password`` + or ``False`` if unset. * Alternatively, configure the channels through the Odoo configuration file, like: @@ -50,6 +54,8 @@ http_auth_password = s3cr3t jobrunner_db_host = master-db jobrunner_db_port = 5432 + jobrunner_db_user = userdb + jobrunner_db_password = passdb * Or, if using ``anybox.recipe.odoo``, add this to your buildout configuration: @@ -187,7 +193,7 @@ def _odoo_now(): def _connection_info_for(db_name): db_or_uri, connection_info = odoo.sql_db.connection_info_for(db_name) - for p in ("host", "port"): + for p in ("host", "port", "user", "password"): cfg = os.environ.get( "ODOO_QUEUE_JOB_JOBRUNNER_DB_%s" % p.upper() ) or queue_job_config.get("jobrunner_db_" + p) diff --git a/queue_job/models/base.py b/queue_job/models/base.py index d218d0d777..16f106450a 100644 --- a/queue_job/models/base.py +++ b/queue_job/models/base.py @@ -251,3 +251,22 @@ def _job_store_values(self, job): :return: dictionary for setting job values. """ return {} + + @api.model + def _job_prepare_context_before_enqueue_keys(self): + """Keys to keep in context of stored jobs + Empty by default for backward compatibility. + """ + # TODO: when migrating to 16.0, active the base context keys: + # return ("tz", "lang", "allowed_company_ids", "force_company", "active_test") + return () + + def _job_prepare_context_before_enqueue(self): + """Return the context to store in the jobs + Can be used to keep only safe keys. + """ + return { + key: value + for key, value in self.env.context.items() + if key in self._job_prepare_context_before_enqueue_keys() + } diff --git a/queue_job/models/queue_job.py b/queue_job/models/queue_job.py index c276287084..58debcc150 100644 --- a/queue_job/models/queue_job.py +++ b/queue_job/models/queue_job.py @@ -297,8 +297,9 @@ def open_graph_jobs(self): self.ensure_one() jobs = self.env["queue.job"].search([("graph_uuid", "=", self.graph_uuid)]) - action_jobs = self.env.ref("queue_job.action_queue_job") - action = action_jobs.read()[0] + action = self.env["ir.actions.act_window"]._for_xml_id( + "queue_job.action_queue_job" + ) action.update( { "name": _("Jobs for graph %s") % (self.graph_uuid), diff --git a/queue_job/readme/USAGE.rst b/queue_job/readme/USAGE.rst index 980cb126fb..743da10236 100644 --- a/queue_job/readme/USAGE.rst +++ b/queue_job/readme/USAGE.rst @@ -242,6 +242,30 @@ Based on this configuration, we can tell that: * retries 10 to 15 postponed 30 seconds later * all subsequent retries postponed 5 minutes later +**Job Context** + +The context of the recordset of the job, or any recordset passed in arguments of +a job, is transferred to the job according to an allow-list. + +The default allow-list is empty for backward compatibility. The allow-list can +be customized in ``Base._job_prepare_context_before_enqueue_keys``. + +Example: + +.. code-block:: python + + class Base(models.AbstractModel): + + _inherit = "base" + + @api.model + def _job_prepare_context_before_enqueue_keys(self): + """Keys to keep in context of stored jobs + + Empty by default for backward compatibility. + """ + return ("tz", "lang", "allowed_company_ids", "force_company", "active_test") + **Bypass jobs on running Odoo** When you are developing (ie: connector modules) you might want diff --git a/queue_job/static/description/index.html b/queue_job/static/description/index.html index f2e3f6d071..e1e4554d1f 100644 --- a/queue_job/static/description/index.html +++ b/queue_job/static/description/index.html @@ -3,7 +3,7 @@ - + Job Queue