From e99662c9eaf7101e84e8add5e28da90b168de279 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 05 2019 15:17:21 +0000 Subject: Add support for fedora-messaging in pagure This effectively port pagure to the new messaging app used in Fedora relying on AMQP. As for the other messaging notifications this relies on a dedicated configuration key. However, projects will reuse the "fedmsg" option key. Signed-off-by: Pierre-Yves Chibon --- diff --git a/doc/configuration.rst b/doc/configuration.rst index 494b468..c8009c6 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -1069,6 +1069,15 @@ This configuration key allows to turn on or off notifications via `fedmsg Defaults to: ``False``. +FEDORA_MESSAGING_NOTIFICATIONS +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +This configuration key allows to turn on or off sending notifications via +`fedora-messaging <>`_. + +Defaults to: ``False``. + + ALWAYS_FEDMSG_ON_COMMITS ~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/pagure/lib/notify.py b/pagure/lib/notify.py index 17c15c0..d64455e 100644 --- a/pagure/lib/notify.py +++ b/pagure/lib/notify.py @@ -64,6 +64,31 @@ def fedmsg_publish(*args, **kwargs): # pragma: no cover _log.exception("Error sending fedmsg") +def fedora_messaging_publish(topic, message): # pragma: no cover + """ Try to publish a message on AMPQ using fedora-messaging. """ + if not pagure_config.get("FEDORA_MESSAGING_NOTIFICATIONS", False): + return + + try: + import fedora_messaging.api + import fedora_messaging.exceptions + + msg = fedora_messaging.api.Message( + topic="pagure.{}".format(topic), + body=message, + ) + fedora_messaging.api.publish(msg) + except Pfedora_messaging.exceptions.ublishReturned as e: + log.warning( + "Fedora Messaging broker rejected message %s: %s", + msg.id, e + ) + except fedora_messaging.exceptions.ConnectionException as e: + log.warning("Error sending message %s: %s", msg.id, e) + except Exception: + _log.exception("Error sending fedora-messaging message") + + stomp_conn = None @@ -165,6 +190,7 @@ def log(project, topic, msg, webhook=True): and not project.private ): fedmsg_publish(topic, msg) + fedora_messaging_publish(topic, msg) # Send stomp notification (if stomp is there and set-up) if not project or (