diff --git a/roles/koji_hub/templates/fedmsg-koji-plugin.py b/roles/koji_hub/templates/fedmsg-koji-plugin.py index 19a344a985..2ba4ffc2fc 100644 --- a/roles/koji_hub/templates/fedmsg-koji-plugin.py +++ b/roles/koji_hub/templates/fedmsg-koji-plugin.py @@ -5,6 +5,7 @@ # Ralph Bean # Mike Bonnet +from koji.context import context from koji.plugin import callbacks from koji.plugin import callback from koji.plugin import ignore_error @@ -130,7 +131,7 @@ def get_message_body(topic, *args, **kws): ] ]) @ignore_error -def send_message(cbtype, *args, **kws): +def queue_message(cbtype, *args, **kws): if cbtype.startswith('post'): msgtype = cbtype[4:] else: @@ -178,4 +179,22 @@ def send_message(cbtype, *args, **kws): body = scrub(body) +{% if env != 'staging' %} + # Send the messages immediately. fedmsg.publish(topic=topic, msg=body, modname='buildsys') +{% else %} + # Queue the message for later. + # It will only get sent after postCommit is called. + messages = getattr(context, 'fedmsg_plugin_messages', []) + messages.append(dict(topic=topic, msg=body, modname='buildsys')) + context.fedmsg_plugin_messages = messages + + +# Meanwhile, postCommit actually sends messages. +@callback('postCommit') +@ignore_error +def send_messages(cbtype, *args, **kws): + messages = getattr(context, 'fedmsg_plugin_messages', []) + for message in messages: + fedmsg.publish(**message) +{% endif %}