From bf4f1112181d3c9d212834cc8ec1acf7ea5c4c24 Mon Sep 17 00:00:00 2001 From: Sayan Chowdhury Date: Apr 11 2019 12:08:04 +0000 Subject: Start processing those messages Signed-off-by: Sayan Chowdhury --- diff --git a/joystick/__init__.py b/joystick/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/joystick/__init__.py diff --git a/joystick/consumers/fedora_messaging_consumer.py b/joystick/consumers/fedora_messaging_consumer.py index 1ad58eb..8936687 100644 --- a/joystick/consumers/fedora_messaging_consumer.py +++ b/joystick/consumers/fedora_messaging_consumer.py @@ -21,4 +21,15 @@ class JoyStickController(object): body = msg.body if topic.endswith("pungi.compose.status.change"): - print(message.body) + _log.debug("Processing %r" % (msg.id)) + if body['status'] not in self.valid_status: + _log.debug("%s is not a valid status" % msg_info["status"]) + return + + compose_id = body['compose_id'] + respin = body['respin'] + compose_date = body['compose_date'] + release_version = body['release_version'] + else: + _log.debug("Dropping %r" % (topic, msg.id)) + pass diff --git a/scripts/fedora-messaging-replay.py b/scripts/fedora-messaging-replay.py new file mode 100644 index 0000000..4b93ec5 --- /dev/null +++ b/scripts/fedora-messaging-replay.py @@ -0,0 +1,69 @@ +#!/usr/bin/python3 +""" +This script can republish any message in datagrepper specified by message id. + +See: https://apps.fedoraproject.org/datagrepper +""" + +import requests +import argparse +from fedora_messaging import api, message as fm_message + +URL_TEMPLATE = "https://apps.fedoraproject.org/datagrepper/id?id={}&is_raw=true" + + +def parse_arguments(): + """ + Parse arguments and returns parsed msg_id. + + Returns: + (str) Message id + """ + + parser = argparse.ArgumentParser(description="Replays messages from datagrepper") + parser.add_argument("msg_id", help="Message of the id to be replayed") + + args = parser.parse_args() + + if not args.msg_id: + parser.print_help() + exit(1) + + return args.msg_id + + +def get_message(msg_id): + """ + Get JSON representation of message from datagrepper. + + Params: + msg_id (str): Message id of the message that should be retrieved + + Returns: + (dict) JSON representation of the message + """ + url = URL_TEMPLATE.format(msg_id) + + response = requests.get(url, timeout=30) + message = response.json() + + return message + + +def publish(message): + """ + Publish message through fedora-messaging. + + Params: + message (dict): JSON representation of the message + """ + msg = fm_message.Message(topic=message["topic"], body=message["msg"]) + + api.publish(msg) + + +if __name__ == "__main__": + msg_id = parse_arguments() + message = get_message(msg_id) + publish(message) +