Skip to content

Commit 4805f13

Browse files
committed
[IMP] queue_job: Configure default subchannel capacity.
This adds a new `subcapacity` option to channels that allows the configuration of the default capacity for autocreated child channels. For example, environment `ODOO_QUEUE_JOB_CHANNELS=root:8:subcapacity=1` would set the capacity of an autocreated `root.sub` channel to 1.
1 parent d198792 commit 4805f13

1 file changed

Lines changed: 28 additions & 4 deletions

File tree

queue_job/jobrunner/channels.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,15 @@ class Channel:
404404
without risking to overflow the system.
405405
"""
406406

407-
def __init__(self, name, parent, capacity=None, sequential=False, throttle=0):
407+
def __init__(
408+
self,
409+
name,
410+
parent,
411+
capacity=None,
412+
sequential=False,
413+
throttle=0,
414+
def_sub_capacity=None,
415+
):
408416
self.name = name
409417
self.parent = parent
410418
if self.parent:
@@ -414,9 +422,10 @@ def __init__(self, name, parent, capacity=None, sequential=False, throttle=0):
414422
self._running = set()
415423
self._failed = set()
416424
self._pause_until = 0 # utc seconds since the epoch
417-
self.capacity = capacity
425+
self.capacity = capacity or (parent and parent.def_sub_capacity)
418426
self.throttle = throttle # seconds
419427
self.sequential = sequential
428+
self.def_sub_capacity = def_sub_capacity
420429

421430
@property
422431
def sequential(self):
@@ -433,11 +442,13 @@ def configure(self, config):
433442
434443
* capacity
435444
* sequential
445+
* def_sub_capacity
436446
* throttle
437447
"""
438448
assert self.fullname.endswith(config["name"])
439449
self.capacity = config.get("capacity", None)
440450
self.sequential = bool(config.get("sequential", False))
451+
self.def_sub_capacity = config.get("def_sub_capacity", None)
441452
self.throttle = int(config.get("throttle", 0))
442453
if self.sequential and self.capacity != 1:
443454
raise ValueError("A sequential channel must have a capacity of 1")
@@ -897,7 +908,16 @@ def parse_simple_config(cls, config_string):
897908
f"Invalid channel config {config_string}: "
898909
f"duplicate key {k}"
899910
)
900-
config[k] = v
911+
if k == "def_sub_capacity":
912+
try:
913+
config[k] = int(v)
914+
except Exception as ex:
915+
raise ValueError(
916+
f"Invalid channel config {config_string}: "
917+
f"invalid def_sub_capacity {v}"
918+
) from ex
919+
else:
920+
config[k] = v
901921
else:
902922
config["capacity"] = 1
903923
res.append(config)
@@ -910,16 +930,20 @@ def simple_configure(self, config_string):
910930
>>> c = cm.get_channel_by_name('root')
911931
>>> c.capacity
912932
1
913-
>>> cm.simple_configure('root:4,autosub.sub:2,seq:1:sequential')
933+
>>> cm.simple_configure('root:4,defsub:def_sub_capacity:3,autosub.sub:2,seq:1:sequential')
914934
>>> cm.get_channel_by_name('root').capacity
915935
4
916936
>>> cm.get_channel_by_name('root').sequential
917937
False
938+
>>> cm.get_channel_by_name('root').def_sub_capacity
918939
>>> cm.get_channel_by_name('root.autosub').capacity
940+
>>> cm.get_channel_by_name('root.autosub').def_sub_capacity
941+
3
919942
>>> cm.get_channel_by_name('root.autosub.sub').capacity
920943
2
921944
>>> cm.get_channel_by_name('root.autosub.sub').sequential
922945
False
946+
>>> cm.get_channel_by_name('root.autosub.sub').def_sub_capacity
923947
>>> cm.get_channel_by_name('autosub.sub').capacity
924948
2
925949
>>> cm.get_channel_by_name('seq').capacity

0 commit comments

Comments
 (0)