]> git.pld-linux.org Git - projects/pld-builder.new.git/commitdiff
fedmsg integration
authorElan Ruusamäe <glen@pld-linux.org>
Sat, 19 Mar 2016 22:40:09 +0000 (00:40 +0200)
committerElan Ruusamäe <glen@pld-linux.org>
Mon, 19 Dec 2016 20:34:58 +0000 (22:34 +0200)
PLD_Builder/messagebus.py [new file with mode: 0644]
PLD_Builder/request.py
PLD_Builder/request_handler.py
PLD_Builder/srpm_builder.py

diff --git a/PLD_Builder/messagebus.py b/PLD_Builder/messagebus.py
new file mode 100644 (file)
index 0000000..781cff9
--- /dev/null
@@ -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",
+    )
index dcfd8e72039cc81391ab9f715e6c3c7513f36c82..eba63fc248e247644ee3ac55f23b84f9b2e9ee22 100644 (file)
@@ -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":
index 033cf39d8760b4c605db7a478a04be9beaedbd4e..45153eab89b6792cdd4f24e41e4b064f2ae1e14b 100644 (file)
@@ -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'" \
index a343587e45b2983478f37d39fbb5b7a88fa9572d..a99b7e384ebf338fc0b5dcbba8211f5f431bbb6a 100644 (file)
@@ -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):
This page took 0.130446 seconds and 4 git commands to generate.