#67 Port elections to fedora-messaging and off fedmsg
Merged 4 years ago by pingou. Opened 4 years ago by pingou.

file removed
-20
@@ -1,20 +0,0 @@ 

- """ This is an example pkgdb configuration for fedmsg.

- By convention, it is normally installed as ``/etc/fedmsg.d/pkgdb.py``

- 

- For Fedora Infrastructure, our own version of this file is kept in

- ``puppet/modules/fedmsg/templates/fedmsg.d/``

- 

- It needs to be globally available so remote consumers know how to find the

- pkgdb producer (wsgi process).

- """

- 

- import socket

- hostname = socket.gethostname().split('.')[0]

- 

- config = dict(

-     endpoints={

-         "fedora_elections.%s" % hostname: [

-             "tcp://127.0.0.1:3005",

-         ],

-     },

- )

@@ -0,0 +1,15 @@ 

+ # Example configuraton for Fedora Messaging

+ # More information on how to use it or what to do with it at:

+ # https://fedora-messaging.readthedocs.io/en/stable/configuration.html

+ 

+ # Broker address

+ amqp_url = "amqp://"

+ 

+ # Authentication is TLS-based

+ [tls]

+ ca_cert = "/etc/pki/tls/certs/ca-bundle.crt"

+ keyfile = "/my/client/key.pem"

+ certfile = "/my/client/cert.pem"

+ 

+ [client_properties]

+ app = "elections"

@@ -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)

file modified
+1
@@ -3,6 +3,7 @@ 

  Flask>=0.10

  flask-oidc

  Flask-wtf

+ fedora-messaging

  kitchen

  python-fedora

  SQLAlchemy