From 8e27fe16fe954b8317f7978b48d0fe7d88ee3c66 Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Fri, 29 Sep 2017 13:07:06 -0400 Subject: [PATCH] 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. --- module_build_service/messaging.py | 10 +++++----- module_build_service/scheduler/consumer.py | 5 ++++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/module_build_service/messaging.py b/module_build_service/messaging.py index 61624937..7b4f3a9b 100644 --- a/module_build_service/messaging.py +++ b/module_build_service/messaging.py @@ -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 diff --git a/module_build_service/scheduler/consumer.py b/module_build_service/scheduler/consumer.py index 318c60a1..af856eb4 100644 --- a/module_build_service/scheduler/consumer.py +++ b/module_build_service/scheduler/consumer.py @@ -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))