Skip to content

Commit 63ee43c

Browse files
committed
fixup! fixup! fixup! fixup! fixup! queue_job: wip hot reload of channel managers by DB
1 parent 3407603 commit 63ee43c

2 files changed

Lines changed: 53 additions & 4 deletions

File tree

queue_job/jobrunner/runner.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def _root_capacity_from_channels_config(config_string):
8080
return 1
8181

8282

83-
def _max_capacity(channel_config_string: str | None = None) -> int:
83+
def _max_capacity() -> int:
8484
"""Maximum number of jobs running at the same time across all databases
8585
8686
If a channels server-side configuration exists, it is equivalent to the
@@ -93,9 +93,7 @@ def _max_capacity(channel_config_string: str | None = None) -> int:
9393
If none is configured, the max capacity is 0.
9494
"""
9595
if _server_side_channels_configured():
96-
if channel_config_string is None:
97-
channel_config_string = _channels()
98-
return _root_capacity_from_channels_config(channel_config_string)
96+
return _root_capacity_from_channels_config(_channels())
9997

10098
value = os.environ.get("ODOO_QUEUE_JOB_MAX_CAPACITY") or queue_job_config.get(
10199
"max_capacity"

queue_job/tests/test_runner_runner.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)
33
import doctest
44
import os
5+
from unittest import mock
56

67
from odoo.tests import BaseCase, tagged
78

@@ -61,3 +62,53 @@ def test_runner_file_closed_write_descriptor(self):
6162

6263
self.assertFalse(self._is_open_file_descriptor(read_fd))
6364
self.assertFalse(self._is_open_file_descriptor(write_fd))
65+
66+
def test_max_capacity_from_env_channels(self):
67+
with (
68+
mock.patch.dict(
69+
os.environ, {"ODOO_QUEUE_JOB_CHANNELS": "root:7,sub:2"}, clear=True
70+
),
71+
mock.patch.object(runner, "queue_job_config", {}),
72+
):
73+
self.assertEqual(runner._max_capacity(), 7)
74+
75+
def test_max_capacity_from_env_channels_without_root(self):
76+
with (
77+
mock.patch.dict(
78+
os.environ, {"ODOO_QUEUE_JOB_CHANNELS": "sub:2"}, clear=True
79+
),
80+
mock.patch.object(runner, "queue_job_config", {}),
81+
):
82+
self.assertEqual(runner._max_capacity(), 1)
83+
84+
def test_max_capacity_from_env(self):
85+
with (
86+
mock.patch.dict(
87+
os.environ, {"ODOO_QUEUE_JOB_MAX_CAPACITY": "5"}, clear=True
88+
),
89+
mock.patch.object(runner, "queue_job_config", {}),
90+
):
91+
self.assertEqual(runner._max_capacity(), 5)
92+
93+
def test_max_capacity_from_odoo_config(self):
94+
with (
95+
mock.patch.dict(os.environ, {}, clear=True),
96+
mock.patch.object(runner, "queue_job_config", {"max_capacity": "3"}),
97+
):
98+
self.assertEqual(runner._max_capacity(), 3)
99+
100+
def test_max_capacity_env_priority_over_odoo_config(self):
101+
with (
102+
mock.patch.dict(
103+
os.environ, {"ODOO_QUEUE_JOB_MAX_CAPACITY": "5"}, clear=True
104+
),
105+
mock.patch.object(runner, "queue_job_config", {"max_capacity": "3"}),
106+
):
107+
self.assertEqual(runner._max_capacity(), 5)
108+
109+
def test_max_capacity_default(self):
110+
with (
111+
mock.patch.dict(os.environ, {}, clear=True),
112+
mock.patch.object(runner, "queue_job_config", {}),
113+
):
114+
self.assertEqual(runner._max_capacity(), 0)

0 commit comments

Comments
 (0)