From 1099752c900307217d07a17eaf6d9589f7266350 Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Thu, 30 Jun 2016 13:23:30 -0400 Subject: [PATCH] Also "listen" for messaging. --- rida/messaging.py | 22 +++++++++++++++++++++- ridad.py | 18 +++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/rida/messaging.py b/rida/messaging.py index 5b31b1ec..44eddfee 100644 --- a/rida/messaging.py +++ b/rida/messaging.py @@ -25,21 +25,41 @@ def publish(topic, msg, backend, modname='rida'): + """ Publish a single message to a given backend, and return. """ try: handler = _messaging_backends[backend]['publish'] except KeyError: raise KeyError("No messaging backend found for %r" % backend) return handler(topic, msg, modname=modname) +def listen(backend, **kwargs): + """ Yield messages from a given messaging backend. + + The ``**kwargs`` arguments will be passed on to the backend to do some + backend-specific connection handling, throttling, or filtering. + """ + try: + handler = _messaging_backends[backend]['listen'] + except KeyError: + raise KeyError("No messaging backend found for %r" % backend) + + for event in handler(**kwargs): + yield event + def _fedmsg_publish(topic, msg, modname): import fedmsg return fedmsg.publish(topic=topic, msg=msg, modname=modname) +def _fedmsg_listen(**kwargs): + import fedmsg + for name, endpoint, topic, msg in fedmsg.tail_messages(**kwargs): + yield msg + _messaging_backends = { 'fedmsg': { 'publish': _fedmsg_publish, - #'listen': _fedmsg_listen, # For later... + 'listen': _fedmsg_listen, }, } diff --git a/ridad.py b/ridad.py index c7182cc5..430fc094 100755 --- a/ridad.py +++ b/ridad.py @@ -23,6 +23,7 @@ # SOFTWARE. # # Written by Petr Ĺ abata +# Ralph Bean """The module build orchestrator for Modularity, the builder. @@ -30,10 +31,25 @@ This is the main component of the orchestrator and is responsible for proper scheduling component builds in the supported build systems. """ -# TODO: Load configuration. +import rida.config +import rida.messaging + +# TODO: Load the config file from environment +config = rida.config.from_file("rida.conf") + # TODO: Listen for bus messages from build systems about builds being done. +for msg in rida.messaging.listen(backend=config.messaging): + print("Saw %r with %r" % (msg['topic'], msg)) + if '.buildsys.build.state.change' in msg['topic']: + print("A build changed state in koji!!") + elif '.rida.module.state.change' in msg['topic']: + print("Our frontend says that a module changed state!!") + else: + pass + # TODO: Periodically check the state of the build systems' tasks, in case some # messages got lost. +# XXX - should we just do this with a cronjob external to this process? # TODO: Emit messages about the module build being done. # TODO; Watch the database and process modules in the wait state. # TODO: Construct the name of the tag/target according to the policy and record