Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions queue_job/jobrunner/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,9 @@ def get_channel_from_config(self, config):
_logger.info("Configured channel: %s", channel)
return channel

def get_channel_by_name(self, channel_name, autocreate=False):
def get_channel_by_name(
self, channel_name, autocreate=False, parent_fallback=False
):
"""Return a Channel object by its name.

If it does not exist and autocreate is True, it is created
Expand Down Expand Up @@ -980,16 +982,36 @@ def get_channel_by_name(self, channel_name, autocreate=False):
>>> c = cm.get_channel_by_name('sub')
>>> c.fullname
'root.sub'
>>> c = cm.get_channel_by_name('root.sub.not.configured', parent_fallback=True)
>>> c.fullname
'root.sub.sub.not.configured'
"""
if not channel_name or channel_name == self._root_channel.name:
return self._root_channel
if not channel_name.startswith(self._root_channel.name + "."):
channel_name = self._root_channel.name + "." + channel_name
if channel_name in self._channels_by_name:
return self._channels_by_name[channel_name]
if not autocreate:
if not autocreate and not parent_fallback:
raise ChannelNotFound("Channel %s not found" % channel_name)
parent = self._root_channel
if parent_fallback:
# Look for first direct parent w/ config.
# Eg: `root.edi.foo.baz` will falback on `root.edi.foo`
# or `root.edi` or `root` in sequence
parent_name = channel_name
while True:
parent_name = parent_name.rsplit(".", 1)[:-1][0]
if parent_name == self._root_channel.name:
break
if parent_name in self._channels_by_name:
parent = self._channels_by_name[parent_name]
_logger.debug(
"%s has no specific configuration: using %s",
channel_name,
parent_name,
)
break
for subchannel_name in channel_name.split(".")[1:]:
subchannel = parent.get_subchannel_by_name(subchannel_name)
if not subchannel:
Expand All @@ -1001,13 +1023,7 @@ def get_channel_by_name(self, channel_name, autocreate=False):
def notify(
self, db_name, channel_name, uuid, seq, date_created, priority, eta, state
):
try:
channel = self.get_channel_by_name(channel_name)
except ChannelNotFound:
_logger.warning(
"unknown channel %s, using root channel for job %s", channel_name, uuid
)
channel = self._root_channel
channel = self.get_channel_by_name(channel_name, parent_fallback=True)
job = self._jobs_by_uuid.get(uuid)
if job:
# db_name is invariant
Expand Down
1 change: 1 addition & 0 deletions queue_job/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
* Tatiana Deribina <tatiana.deribina@avoin.systems>
* Souheil Bejaoui <souheil.bejaoui@acsone.eu>
* Eric Antones <eantones@nuobit.com>
* Simone Orsi <simone.orsi@camptocamp.com>