[projects/pld-builder.new] fedmsg integration

glen glen at pld-linux.org
Mon Dec 19 21:35:46 CET 2016


commit c39f140214464ac8d579ae4b275d412c29a5c3e3
Author: Elan Ruusamäe <glen at pld-linux.org>
Date:   Sun Mar 20 00:40:09 2016 +0200

    fedmsg integration

 PLD_Builder/messagebus.py      | 18 +++++++++++++++
 PLD_Builder/request.py         | 50 ++++++++++++++++++++++++++++++++++++++++++
 PLD_Builder/request_handler.py |  3 +++
 PLD_Builder/srpm_builder.py    |  4 ++++
 4 files changed, 75 insertions(+)
---
diff --git a/PLD_Builder/messagebus.py b/PLD_Builder/messagebus.py
new file mode 100644
index 0000000..781cff9
--- /dev/null
+++ b/PLD_Builder/messagebus.py
@@ -0,0 +1,18 @@
+#!/usr/bin/python
+# I would name this file as fedmsg,
+# but don't know how to import 'fedmsg' from system dir and from local dir
+
+import fedmsg
+import fedmsg.config
+
+config = fedmsg.config.load_config([], None)
+config['active'] = True
+config['endpoints']['relay_inbound'] = config['relay_inbound']
+fedmsg.init(name='relay_inbound', cert_prefix='builder', **config)
+
+def notify(topic, **kwargs):
+    fedmsg.publish(
+        topic=topic,
+        msg=dict(kwargs),
+        modname="builder",
+    )
diff --git a/PLD_Builder/request.py b/PLD_Builder/request.py
index dcfd8e7..eba63fc 100644
--- a/PLD_Builder/request.py
+++ b/PLD_Builder/request.py
@@ -116,6 +116,23 @@ class Group:
             b.dump(f)
         f.write("\n")
 
+    # return structure usable for json encoding
+    def dump_json(self):
+        batches = []
+        for b in self.batches:
+            batches.append(b.dump_json())
+
+        return dict(
+            no=self.no,
+            id=self.id,
+            time=self.time,
+            requester=self.requester,
+            priority=self.priority,
+            max_jobs=self.max_jobs,
+            flags=self.flags,
+            batches=batches,
+        )
+
     def dump_html(self, f):
         f.write(
             "<div id=\"%(no)d\" class=\"request %(flags)s\">\n"
@@ -272,6 +289,30 @@ class Batch:
     def is_command(self):
         return self.command != ""
 
+    # return structure usable for json encoding
+    def dump_json(self):
+        return dict(
+            command=self.command,
+            command_flags=self.command_flags,
+
+            spec=self.spec,
+            branch=self.branch,
+            package=self.spec[:-5],
+            src_rpm=self.src_rpm,
+
+            bconds_with=self.bconds_with,
+            bconds_without=self.bconds_without,
+
+            kernel=self.kernel,
+            target=self.target,
+            defines=self.defines,
+
+            builders=self.builders,
+            builders_status=self.builders_status,
+            builders_status_time=self.builders_status_time,
+            builders_status_buildtime=self.builders_status_buildtime,
+        )
+
     def dump_html(self, f, rid):
         f.write("<li>\n")
         if self.is_command():
@@ -511,6 +552,15 @@ class Notification:
             else:
                 log.panic("xml: evil notification child (%s)" % c.nodeName)
 
+    # return structure usable for json encoding
+    def dump_json(self):
+        return dict(
+            id=self.group_id,
+            builder=self.builder,
+            batches=self.batches,
+            batches_buildtime=self.batches_buildtime,
+        )
+
     def apply_to(self, q):
         for r in q.requests:
             if r.kind == "group":
diff --git a/PLD_Builder/request_handler.py b/PLD_Builder/request_handler.py
index 033cf39..45153ea 100644
--- a/PLD_Builder/request_handler.py
+++ b/PLD_Builder/request_handler.py
@@ -21,6 +21,7 @@ from lock import lock
 from bqueue import B_Queue
 from config import config, init_conf
 from mailer import Message
+import messagebus
 
 def check_double_id(id):
     id_nl = id + "\n"
@@ -197,8 +198,10 @@ def handle_request(req, filename = None):
     status.push("request from %s" % user.login)
     r = request.parse_request(body)
     if r.kind == 'group':
+        messagebus.notify(topic="request.group", user=user.login, **r.dump_json())
         handle_group(r, user)
     elif r.kind == 'notification':
+        messagebus.notify(topic="request.notify", user=user.login, **r.dump_json())
         handle_notification(r, user)
     else:
         msg = "%s: don't know how to handle requests of this kind '%s'" \
diff --git a/PLD_Builder/srpm_builder.py b/PLD_Builder/srpm_builder.py
index a343587..a99b7e3 100644
--- a/PLD_Builder/srpm_builder.py
+++ b/PLD_Builder/srpm_builder.py
@@ -24,6 +24,7 @@ import notify
 import status
 import build
 import report
+import messagebus
 
 from lock import lock
 from bqueue import B_Queue
@@ -96,6 +97,7 @@ def build_srpm(r, b):
         return "FAIL"
 
     status.push("building %s" % b.spec)
+#    messagebus.notify(topic="build_srpm.start", spec=b.spec, flags=r.flags, batch=b, request=r)
 
     b.src_rpm = ""
     builder_opts = "-nu -nm --nodeps --http --define \'_pld_builder 1\'"
@@ -140,6 +142,8 @@ def build_srpm(r, b):
 
     if res:
         res = "FAIL"
+
+#    messagebus.notify(topic="build_srpm.finish", spec=b.spec)
     return res
 
 def handle_request(r):
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/projects/pld-builder.new.git/commitdiff/c39f140214464ac8d579ae4b275d412c29a5c3e3



More information about the pld-cvs-commit mailing list