|
2 | 2 | # Copyright 2015-2016 Camptocamp SA |
3 | 3 | # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html) |
4 | 4 | import logging |
| 5 | +import os |
5 | 6 | from functools import total_ordering |
6 | 7 | from heapq import heappop, heappush |
7 | 8 | from weakref import WeakValueDictionary |
8 | 9 |
|
9 | 10 | from ..exception import ChannelNotFound |
10 | 11 | from ..job import CANCELLED, DONE, ENQUEUED, FAILED, PENDING, STARTED, WAIT_DEPENDENCIES |
| 12 | +from . import queue_job_config |
11 | 13 |
|
12 | 14 | NOT_DONE = (WAIT_DEPENDENCIES, PENDING, ENQUEUED, STARTED, FAILED) |
13 | 15 |
|
@@ -411,7 +413,7 @@ def __init__(self, name, parent, capacity=None, sequential=False, throttle=0): |
411 | 413 | self._running = SafeSet() |
412 | 414 | self._failed = SafeSet() |
413 | 415 | self._pause_until = 0 # utc seconds since the epoch |
414 | | - self.capacity = capacity |
| 416 | + self.capacity = capacity or _default_subchannel_capacity() |
415 | 417 | self.throttle = throttle # seconds |
416 | 418 | self.sequential = sequential |
417 | 419 |
|
@@ -933,7 +935,7 @@ def get_channel_from_config(self, config): |
933 | 935 | If the channel does not exist it is created. |
934 | 936 | The configuration is applied on the channel before returning it. |
935 | 937 | 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 |
937 | 939 | (except for the root channel, which defaults to a capacity of 1 |
938 | 940 | when not configured explicity). |
939 | 941 | """ |
@@ -1077,3 +1079,11 @@ def get_jobs_to_run(self, now): |
1077 | 1079 |
|
1078 | 1080 | def get_wakeup_time(self): |
1079 | 1081 | 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) |
0 commit comments