Skip to content

Commit 0ae333a

Browse files
author
Milan Topuzov
committed
queue_job: address review nits
1 parent ae5a9eb commit 0ae333a

File tree

6 files changed

+32
-39
lines changed

6 files changed

+32
-39
lines changed

queue_job/jobrunner/runner.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -472,11 +472,9 @@ def from_environ_or_config(cls):
472472
return runner
473473

474474
def get_db_names(self):
475-
db_name_opt = config["db_name"]
476-
if db_name_opt:
477-
if isinstance(db_name_opt, (list, tuple, set)):
478-
return list(db_name_opt)
479-
return [n for n in str(db_name_opt).split(",") if n]
475+
db_names = config["db_name"] or []
476+
if db_names:
477+
return list(db_names)
480478
return odoo.service.db.list_dbs(True)
481479

482480
def close_databases(self, remove_jobs=True):

queue_job/models/base.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,3 @@ def _job_prepare_context_before_enqueue(self):
268268
for key, value in self.env.context.items()
269269
if key in self._job_prepare_context_before_enqueue_keys()
270270
}
271-
272-
# Note: no local _patch_method helper; if needed, patch methods
273-
# directly in _register_hook as shown above.

queue_job/models/queue_job.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,10 @@ class QueueJob(models.Model):
129129

130130
def init(self):
131131
cr = self.env.cr
132-
index_1 = "queue_job_identity_key_state_partial_index"
133-
index_2 = "queue_job_channel_date_done_date_created_index"
134132
# Used by Job.job_record_with_same_identity_key
135133
create_index(
136134
cr,
137-
index_1,
135+
"queue_job_identity_key_state_partial_index",
138136
"queue_job",
139137
["identity_key"],
140138
where=(
@@ -146,25 +144,25 @@ def init(self):
146144
# Used by <queue.job>.autovacuum
147145
create_index(
148146
cr,
149-
index_2,
147+
"queue_job_channel_date_done_date_created_index",
150148
"queue_job",
151149
["channel", "date_done", "date_created"],
152150
comment="Queue Job: index to accelerate autovacuum",
153151
)
154152

155153
@api.depends("dependencies")
156154
def _compute_dependency_graph(self):
157-
uuids = [uuid for uuid in self.mapped("graph_uuid") if uuid]
158-
ids_per_graph_uuid = {}
159-
if uuids:
160-
rows = self.env["queue.job"]._read_group(
161-
[("graph_uuid", "in", uuids)],
162-
groupby=["graph_uuid"],
163-
aggregates=["id:recordset"],
155+
graph_uuids = [uuid for uuid in self.mapped("graph_uuid") if uuid]
156+
if graph_uuids:
157+
ids_per_graph_uuid = dict(
158+
self.env["queue.job"]._read_group(
159+
[("graph_uuid", "in", graph_uuids)],
160+
groupby=["graph_uuid"],
161+
aggregates=["id:array_agg"],
162+
)
164163
)
165-
# rows -> list of tuples: (graph_uuid, recordset)
166-
for graph_uuid, recs in rows:
167-
ids_per_graph_uuid[graph_uuid] = recs.ids
164+
else:
165+
ids_per_graph_uuid = {}
168166
for record in self:
169167
if not record.graph_uuid:
170168
record.dependency_graph = {}
@@ -224,12 +222,13 @@ def _dependency_graph_vis_node(self):
224222
def _compute_graph_jobs_count(self):
225223
graph_uuids = [uuid for uuid in self.mapped("graph_uuid") if uuid]
226224
if graph_uuids:
227-
rows = self.env["queue.job"]._read_group(
228-
[("graph_uuid", "in", graph_uuids)],
229-
["graph_uuid"],
230-
["__count"],
225+
count_per_graph_uuid = dict(
226+
self.env["queue.job"]._read_group(
227+
[("graph_uuid", "in", graph_uuids)],
228+
groupby=["graph_uuid"],
229+
aggregates=["__count"],
230+
)
231231
)
232-
count_per_graph_uuid = {graph_uuid: cnt for graph_uuid, cnt in rows}
233232
else:
234233
count_per_graph_uuid = {}
235234
for record in self:

queue_job/tests/common.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,14 @@ def _filtered_enqueued_jobs(self, job_method):
298298

299299
def _format_job_call(self, call):
300300
# Build method argument string (positional and keyword) separately
301-
args_str = ", ".join(f"{arg}" for arg in call.args) if call.args else ""
302-
kwargs_str = (
303-
", ".join(f"{key}={value}" for key, value in call.kwargs.items())
304-
if call.kwargs
305-
else ""
306-
)
307-
method_args = ", ".join(s for s in (args_str, kwargs_str) if s)
301+
method_args_parts = []
302+
if call.args:
303+
method_args_parts.append(", ".join(f"{arg}" for arg in call.args))
304+
if call.kwargs:
305+
method_args_parts.append(
306+
", ".join(f"{key}={value}" for key, value in call.kwargs.items())
307+
)
308+
method_args = ", ".join(method_args_parts)
308309

309310
# Build properties string
310311
props_str = ", ".join(

queue_job/tests/test_json_field.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def test_encoder_date(self):
149149
self.assertEqual(json.loads(value_json), expected)
150150

151151
def test_decoder_date(self):
152-
value_json = '["a", 1, {"_type": "date_isoformat","value": "2017-04-19"}]'
152+
value_json = '["a", 1, {"_type": "date_isoformat", "value": "2017-04-19"}]'
153153
expected = ["a", 1, date(2017, 4, 19)]
154154
value = json.loads(value_json, cls=JobDecoder, env=self.env)
155155
self.assertEqual(value, expected)

test_queue_job/tests/test_job.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ class TestJobsOnTestingMethod(JobCommonCase):
3636
@classmethod
3737
def setUpClass(cls):
3838
super().setUpClass()
39-
User = cls.env["res.users"]
4039
main_company = cls.env.ref("base.main_company")
4140
group_user = cls.env.ref("base.group_user")
42-
cls.demo_user = User.create(
41+
cls.demo_user = cls.env["res.users"].create(
4342
{
4443
"name": "Demo User (Queue)",
4544
"login": "queue_demo_user_3",
@@ -407,10 +406,9 @@ class TestJobs(JobCommonCase):
407406
@classmethod
408407
def setUpClass(cls):
409408
super().setUpClass()
410-
User = cls.env["res.users"]
411409
main_company = cls.env.ref("base.main_company")
412410
group_user = cls.env.ref("base.group_user")
413-
cls.demo_user = User.create(
411+
cls.demo_user = cls.env["res.users"].create(
414412
{
415413
"name": "Demo User (Queue)",
416414
"login": "queue_demo_user_4",

0 commit comments

Comments
 (0)