#179 Port fedocal to fedora-messaging and drop fedmsg support
Merged 4 years ago by pingou. Opened 5 years ago by jlanda.
jlanda/fedocal fedora-messaging  into  master

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

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

- By convention, it is normally installed as ``/etc/fedmsg.d/fedocal.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

- fedocal producer (wsgi process).

- """

- 

- import socket

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

- 

- config = dict(

-     endpoints={

-         "fedocal.%s" % hostname: [

-             "tcp://127.0.0.1:3025",

-         ],

-     },

- )

@@ -1,18 +1,32 @@ 

- """ This is a temporary shim that allows fedmsg to be an optional dependency of

- pkgdb.  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>

  

  """

- from __future__ import unicode_literals, absolute_import, print_function

+ from __future__ import unicode_literals, absolute_import

  

- import warnings

+ import logging

  

+ import fedora_messaging.api

+ 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 err:

-         warnings.warn(str(err))

+         message = fedora_messaging.api.Message(

+             topic='fedocal.%s' % topic,

+             body=msg

+         )

+         fedora_messaging.api.publish(message)

+         _log.debug("Sent to fedora_messaging")

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

\ No newline at end of file

file modified
+11 -30
@@ -26,55 +26,37 @@ 

  This script is meant to be run as a cron job to send the reminders for

  each meeting that asked for it.

  """

- 

+ from __future__ import unicode_literals, absolute_import

  

  import smtplib

  import warnings

+ import logging

  

  from email.mime.text import MIMEText

  

  import fedocal

  import fedocal.fedocallib as fedocallib

+ import fedocal.fedocallib.fedmsgshim as fedmsg

  

- 

- def fedmsg_init():

-     """ Instanciate fedmsg """

-     try:

-         import fedmsg

-         import fedmsg.config

-     except ImportError:

-         warnings.warn("fedmsg ImportError")

-         return

- 

-     config = fedmsg.config.load_config()

-     config['active'] = True

-     config['name'] = 'relay_inbound'

-     config['cert_prefix'] = 'fedocal'

-     fedmsg.init(**config)

- 

+ _log = logging.getLogger(__name__)

  

  def fedmsg_publish(meeting, meeting_id):

-     """ Publish the meeting.reminder messages on fedmsg.

+     """ Publish the meeting.reminder messages on fedora-messaging.

      :arg meeting: a Meeting object from fedocallib.model

      :arg meeting_id: an int representing the meeting identifier in the

          database

      """

-     try:

-         import fedmsg

-     except ImportError:

-         return

+     _log.debug('Publishing a message for %r: %s', topic, msg)

+ 

  

      meeting_dict = meeting.to_json()

      meeting_dict['meeting_id'] = meeting_id

  

-     fedmsg.publish(

-         modname="fedocal",

-         topic="meeting.reminder",

-         msg=dict(

-             meeting=meeting_dict,

-             calendar=meeting.calendar.to_json()

-         ),

+     message = dict(

+         meeting=meeting_dict,

+         calendar=meeting.calendar.to_json()

      )

+     fedmsg.publish('fedocal.reminder', message)

  

  

  def send_reminder_meeting(meeting, meeting_id):
@@ -155,5 +137,4 @@ 

  

  

  if __name__ == '__main__':

-     fedmsg_init()

      send_reminder()

@@ -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 = "fedocal" 

\ No newline at end of file

file modified
+2
@@ -23,3 +23,5 @@ 

  python-openid

  python-openid_cla

  python-openid_teams

+ fedora-messaging

+ 

no initial comment

Why this isn't calling the publish method from fedocal/fedocallib/fedmsgshim.py?

It looks good only one question.

Because fedmsg implementation was not using it either :D

The intent of this commit was just moving from fedmsg to fedora-messaging. No new logic, features etc.

This should be an ongoing work and continue evolving with an fedora-messaging scheme and perhaps a service like in release-monitoring for the periodic jobs instead of a cron script

In this case I'm giving :thumbsup:

@jlanda, could you rebase this PR?

rebased onto 4ab75725d13613fa0c037e3d2b5b7e3745c64609

5 years ago

@jlanda, could you rebase this PR?

done (and toggle changed)

@jlanda considering we're importing other parts of fedocal, I guess it makes sense to re-use the same code path here as well. Could you make the change?

@jlanda considering we're importing other parts of fedocal, I guess it makes sense to re-use the same code path here as well. Could you make the change?

Okido

@pingou Is there anything left to do on this one? or can it be merged?

@pingou Is there anything left to do on this one? or can it be merged?

I need to change the cron file to reuse the same code. I'll work on it today

rebased onto 7b327fb2051e3b00576b07c6b6dae8b6b9308448

4 years ago

rebased onto 8415a1b

4 years ago

Let's get this in, thanks @jlanda !

Pull-Request has been merged by pingou

4 years ago