From 13938765508fa20f0953cf39c1671e1074284b18 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jan 21 2020 11:34:36 +0000 Subject: Add notifications upon test start and end Signed-off-by: Pierre-Yves Chibon --- diff --git a/runner.py b/runner.py index 53b47fa..86e65ca 100644 --- a/runner.py +++ b/runner.py @@ -11,6 +11,8 @@ import sys import time import utils +import fedora_messaging.api +import fedora_messaging.exceptions import toml import monitor_gating @@ -32,6 +34,21 @@ def get_arguments(args): return parser.parse_args(args) +def notify(topic, message): + try: + msg = fedora_messaging.api.Message( + topic="monitor-gating.{}".format(topic), + body=message + ) + fedora_messaging.api.publish(msg) + except fedora_messaging.exceptions.PublishReturned as e: + print(f"Fedora Messaging broker rejected message {msg.id}: {err}") + except fedora_messaging.exceptions.ConnectionException as err: + print(f"Error sending message {msg.id}: {err}") + except Exception as err: + print(f"Error sending fedora-messaging message: {err}") + + def schedule(conf): """ Run the test and schedules the next one. """ delay = conf["delay"] @@ -39,7 +56,23 @@ def schedule(conf): try: #TEST HERE single_args = conf["workflow_single_gating_args"].split() + notify( + topic=f"single-build.start", + message={ + "arguments": single_args, + } + ) output = monitor_gating.main(single_args) + output_text="\n".join(output) + success="[FAILED]" not in output_text + notify( + topic=f"single-build.end.{success}", + message={ + "output": output, + "output_text": output_text, + "success": success, + } + ) print("Tests finished:", datetime.datetime.utcnow()) except Exception as err: print(f"Tests failed with: {err}")