| |
@@ -1,17 +1,31 @@
|
| |
- """ This is a temporary shim that allows fedmsg to be an optional dependency of
|
| |
- elections. If fedmsg is installed, these function calls will try to actually
|
| |
- send messages. If it is not installed, it will return silently.
|
| |
+ """ This is an utility module for sending notifications via fedora-messaging
|
| |
|
| |
:Author: Ralph Bean <rbean@redhat.com>
|
| |
+ :Author: Pierre-Yves Chibon <pingou@pingoured.fr>
|
| |
|
| |
"""
|
| |
|
| |
import warnings
|
| |
+ import logging
|
| |
|
| |
+ from fedora_messaging.api import Message, publish
|
| |
+ from fedora_messaging.exceptions import PublishReturned, ConnectionException
|
| |
|
| |
- def publish(*args, **kwargs): # pragma: no cover
|
| |
+
|
| |
+ _log = logging.getLogger(__name__)
|
| |
+
|
| |
+
|
| |
+ def publish(topic, msg): # pragma: no cover
|
| |
+ _log.debug('Publishing a message for %r: %s', topic, msg)
|
| |
try:
|
| |
- import fedmsg
|
| |
- fedmsg.publish(*args, **kwargs)
|
| |
- except Exception as e:
|
| |
- warnings.warn(str(e))
|
| |
+ message = Message(
|
| |
+ topic='fedora_elections.%s' % topic,
|
| |
+ body=msg
|
| |
+ )
|
| |
+ publish(message)
|
| |
+ except PublishReturned as e:
|
| |
+ _log.exception(
|
| |
+ 'Fedora Messaging broker rejected message %s: %s',
|
| |
+ message.id, e)
|
| |
+ except ConnectionException as e:
|
| |
+ _log.exception('Error sending message %s: %s', message.id, e)
|
| |
Signed-off-by: Pierre-Yves Chibon pingou@pingoured.fr