mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-02-10 08:34:59 +08:00
Raise a special exception for special messages.
Today, we ignore koji messages with a None `task_id` in two ways. First with a conditional, and then with a second check in the message `__init__` method. This is a belt-and-suspenders approach. For other reasons in the UMB messaging plugin, we'd like to put this check in just one place and use a special exception in the initializer instead of in a conditional beforehand.
This commit is contained in:
@@ -35,6 +35,10 @@ except ImportError:
|
||||
from module_build_service import log, conf
|
||||
|
||||
|
||||
class IgnoreMessage(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class BaseMessage(object):
|
||||
def __init__(self, msg_id):
|
||||
"""
|
||||
@@ -141,10 +145,6 @@ class FedmsgMessageParser(MessageParser):
|
||||
build_version = msg_inner_msg.get('version')
|
||||
build_release = msg_inner_msg.get('release')
|
||||
|
||||
if task_id is None:
|
||||
log.debug("Saw a koji build change with no task_id.")
|
||||
return
|
||||
|
||||
msg_obj = KojiBuildChange(
|
||||
msg_id, build_id, task_id, build_new_state, build_name,
|
||||
build_version, build_release)
|
||||
@@ -199,7 +199,7 @@ class KojiBuildChange(BaseMessage):
|
||||
build_version, build_release, module_build_id=None,
|
||||
state_reason=None):
|
||||
if task_id is None:
|
||||
raise ValueError("KojiBuildChange with a null task_id is invalid.")
|
||||
raise IgnoreMessage("KojiBuildChange with a null task_id is invalid.")
|
||||
super(KojiBuildChange, self).__init__(msg_id)
|
||||
self.build_id = build_id
|
||||
self.task_id = task_id
|
||||
|
||||
@@ -169,7 +169,10 @@ class MBSConsumer(fedmsg.consumers.FedmsgConsumer):
|
||||
parser = module_build_service.messaging.\
|
||||
_messaging_backends[conf.messaging].get('parser')
|
||||
if parser:
|
||||
return parser.parse(message)
|
||||
try:
|
||||
return parser.parse(message)
|
||||
except module_build_service.messaging.IgnoreMessage:
|
||||
pass
|
||||
else:
|
||||
raise ValueError('{0} backend does not define a message parser'
|
||||
.format(conf.messaging))
|
||||
|
||||
Reference in New Issue
Block a user