Skip to content

Commit ee6389b

Browse files
committed
[IMP] Make default subchannel capacity configurable.
Either ODOO_QUEUE_JOB_DEFAULT_SUBCHANNEL_CAPACITY may be set as an environment variable, or default_subchannel_capacity may be set in the [queue_job] config file stanza.
1 parent 7c51fcb commit ee6389b

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

queue_job/jobrunner/channels.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
# Copyright 2015-2016 Camptocamp SA
33
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)
44
import logging
5+
import os
56
from functools import total_ordering
67
from heapq import heappop, heappush
78
from weakref import WeakValueDictionary
89

910
from ..exception import ChannelNotFound
1011
from ..job import CANCELLED, DONE, ENQUEUED, FAILED, PENDING, STARTED, WAIT_DEPENDENCIES
12+
from . import queue_job_config
1113

1214
NOT_DONE = (WAIT_DEPENDENCIES, PENDING, ENQUEUED, STARTED, FAILED)
1315

@@ -411,7 +413,7 @@ def __init__(self, name, parent, capacity=None, sequential=False, throttle=0):
411413
self._running = SafeSet()
412414
self._failed = SafeSet()
413415
self._pause_until = 0 # utc seconds since the epoch
414-
self.capacity = capacity
416+
self.capacity = capacity or _default_subchannel_capacity()
415417
self.throttle = throttle # seconds
416418
self.sequential = sequential
417419

@@ -933,7 +935,7 @@ def get_channel_from_config(self, config):
933935
If the channel does not exist it is created.
934936
The configuration is applied on the channel before returning it.
935937
If some of the parent channels are missing when creating a subchannel,
936-
the parent channels are auto created with an infinite capacity
938+
the parent channels are auto created with the default subchannel capacity
937939
(except for the root channel, which defaults to a capacity of 1
938940
when not configured explicity).
939941
"""
@@ -1077,3 +1079,11 @@ def get_jobs_to_run(self, now):
10771079

10781080
def get_wakeup_time(self):
10791081
return self._root_channel.get_wakeup_time()
1082+
1083+
1084+
def _default_subchannel_capacity():
1085+
capacity = os.environ.get(
1086+
"ODOO_QUEUE_JOB_DEFAULT_SUBCHANNEL_CAPACITY"
1087+
) or queue_job_config.get("default_subchannel_capacity")
1088+
if capacity:
1089+
return int(capacity)

queue_job/readme/CONFIGURE.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
- ``ODOO_QUEUE_JOB_CHANNELS=root:4`` or any other channels configuration.
66
The default is ``root:1``
77

8+
- ``ODOO_QUEUE_JOB_DEFAULT_SUBCHANNEL_CAPACITY=1``
9+
The default is infinite capacity.
10+
811
- if ``xmlrpc_port`` is not set: ``ODOO_QUEUE_JOB_PORT=8069``
912

1013
* Start Odoo with ``--load=web,queue_job``
@@ -23,6 +26,7 @@
2326
(...)
2427
[queue_job]
2528
channels = root:2
29+
# default_subchannel_capacity = 1
2630
2731
* Confirm the runner is starting correctly by checking the odoo log file:
2832

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
11
# Copyright 2015-2016 Camptocamp SA
22
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)
33

4+
import os
5+
from unittest.mock import patch
6+
7+
from odoo.tests import BaseCase
8+
49
# pylint: disable=odoo-addons-relative-import
510
# we are testing, we want to test as we were an external consumer of the API
611
from odoo.addons.queue_job.jobrunner import channels
712

813
from .common import load_doctests
914

1015
load_tests = load_doctests(channels)
16+
17+
18+
class TestDefaultSubchannelCapacity(BaseCase):
19+
@patch.dict(os.environ, {"ODOO_QUEUE_JOB_DEFAULT_SUBCHANNEL_CAPACITY": "1"})
20+
def test_default_subchannel_capacity_env(self):
21+
self.assertEqual(channels._default_subchannel_capacity(), 1)
22+
23+
@patch.dict(channels.queue_job_config, {"default_subchannel_capacity": "1"})
24+
def test_default_subchannel_capacity_conf(self):
25+
self.assertEqual(channels._default_subchannel_capacity(), 1)
26+
27+
def test_default_subchannel_capacity_omit(self):
28+
self.assertIs(channels._default_subchannel_capacity(), None)

0 commit comments

Comments
 (0)