[projects/pld-builder.new] binary builders: report each batch as it goes, OK once its files are sent

arekm arekm at pld-linux.org
Thu Nov 12 00:30:01 CET 2026


commit 36820c2fa36752ead7c4e5bda05dfbe236f6b6cd
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Wed Nov 11 23:12:03 2026 +0100

    binary builders: report each batch as it goes, OK once its files are sent
    
    A binary builder reported nothing until the whole request was done,
    and then OK for a batch whose rpms still waited in its ftp queue:
    file_sender sends notifications first and the rpms last, and retries a
    failed upload for hours. Tools that trust the queue, such as
    pfa-mvpkg on the ftp server, took such a build for complete.
    
    A binary builder now sends BUILDING when it starts a batch and
    UPLOADING once it is built. The OK notification names the files the
    batch queued for ftp, and file_sender holds it until they are sent,
    then sends it in the same run. A failed batch is reported at once, not
    at the end of the request. The src builder notifies as before, at the
    end of its request.

 PLD_Builder/build.py       | 15 ++++++++++++---
 PLD_Builder/file_sender.py |  5 +++++
 PLD_Builder/ftp.py         |  7 +++++++
 PLD_Builder/notify.py      | 24 ++++++++++++++++++------
 PLD_Builder/notifyq.py     | 10 ++++++----
 PLD_Builder/rpm_builder.py |  2 +-
 6 files changed, 49 insertions(+), 14 deletions(-)
---
diff --git a/PLD_Builder/build.py b/PLD_Builder/build.py
index 9254edb..df71d30 100644
--- a/PLD_Builder/build.py
+++ b/PLD_Builder/build.py
@@ -6,6 +6,7 @@ import time
 
 import buildlogs
 import chroot
+import ftp
 import log
 import notify
 import path
@@ -54,9 +55,10 @@ def run_command(batch):
         log_command(batch, f"in chroot as {user or config.builder_user}")
         return chroot.run(command, logfile = batch.logfile, user = user, nonet=False)
 
-def build_all(r, build_fnc):
+def build_all(r, build_fnc, notify_now=False):
+    """Run each batch of r; with notify_now the src builder hears of each status as it changes"""
     status.email = r.requester_email
-    notify.begin(r)
+    notify.begin(r, notify_now)
     tmp = path.build_dir + '/' + util.uuid() + "/"
     r.tmp_dir = tmp
     os.mkdir(tmp)
@@ -80,6 +82,7 @@ def build_all(r, build_fnc):
                 util.append_to(batch.logfile, f"request from: {r.requester}")
                 util.append_to(batch.logfile, f"started at: {time.asctime()}")
                 stopwatch.start()
+                notify.progress(batch, "BUILDING")
                 batch.build_failed = run_command(batch)
                 util.append_to(batch.logfile, f"exit status {batch.build_failed}")
                 if batch.build_failed:
@@ -103,13 +106,19 @@ def build_all(r, build_fnc):
             batch.gb_id=r.id
             batch.requester=r.requester
             batch.requester_email=r.requester_email
+            notify.progress(batch, "BUILDING")
+            queued = len(ftp.ids())
             batch.build_failed = build_fnc(r, batch)
             if batch.build_failed:
                 log.notice(f"building {batch.spec} FAILED ({batch.build_failed})")
                 notify.add_batch(batch, batch.build_failed)
             else:
                 log.notice(f"building {batch.spec} OK")
-                notify.add_batch(batch, "OK")
+                # OK only once the files this batch queued for ftp are there
+                files = ftp.ids()[queued:]
+                if files:
+                    notify.progress(batch, "UPLOADING")
+                notify.add_batch(batch, "OK", after=files)
             batch.build_time = stopwatch.stop()
             report.add_pld_builder_info(batch)
             buildlogs.add(batch.logfile, failed = batch.build_failed, id=r.id)
diff --git a/PLD_Builder/file_sender.py b/PLD_Builder/file_sender.py
index 924dfde..a29112c 100644
--- a/PLD_Builder/file_sender.py
+++ b/PLD_Builder/file_sender.py
@@ -153,6 +153,9 @@ def flush_queue(dir):
     # copy of q
     remaining = q[:]
     for d in q:
+        # a notification that waits for files of the ftp queue: not a problem, just not yet
+        if any(os.path.exists(f"{path.ftp_queue_dir}/{id}") for id in d.get('After', '').split()):
+            continue
         err = send_file(d['_file'], d['Target'])
         if err:
             problems[d['_file']] = err
@@ -196,6 +199,8 @@ def main():
     maybe_flush_queue(path.notify_queue_dir)
     maybe_flush_queue(path.buildlogs_queue_dir)
     maybe_flush_queue(path.ftp_queue_dir)
+    # again, for the notifications that waited for the files just sent
+    maybe_flush_queue(path.notify_queue_dir)
 
 if __name__ == '__main__':
     argparse.ArgumentParser(
diff --git a/PLD_Builder/ftp.py b/PLD_Builder/ftp.py
index 5ba00d8..ab6db6f 100644
--- a/PLD_Builder/ftp.py
+++ b/PLD_Builder/ftp.py
@@ -37,6 +37,9 @@ class FTP_Queue:
         st = os.stat(path.ftp_queue_dir + '/' + id)
         self.status += f"{st.st_size:10d} {name}\n"
 
+    def ids(self):
+        return [l['id'] for l in self.queue]
+
     def flush(self):
         def desc(l):
             return f"""Target: {self.url}/{l['name']}
@@ -55,6 +58,10 @@ queue = FTP_Queue()
 def add(f, type="rpm"):
     queue.add(f, type)
 
+def ids():
+    """Ids of the files added so far: a file stays in the ftp queue under its id until it is sent"""
+    return queue.ids()
+
 def flush():
     queue.flush()
 
diff --git a/PLD_Builder/notify.py b/PLD_Builder/notify.py
index 430209e..b8327f0 100644
--- a/PLD_Builder/notify.py
+++ b/PLD_Builder/notify.py
@@ -9,16 +9,26 @@ import notifyq
 import util
 from config import config
 
-# the request the statuses are of
+# the request the statuses are of, and whether each status goes out as soon as it is known
 group = None
+live = False
 
-def begin(g):
-    global group
+def begin(g, now=False):
+    global group, live
     group = g
+    live = now
     notifyq.init(g)
 
-def add_batch(batch, status):
-    """Queue the status of one batch for the src builder; send() sends what is queued"""
+def progress(batch, status):
+    """A status on the way to the final one; only a builder that sends each status at once reports these"""
+    if live:
+        add_batch(batch, status)
+
+def add_batch(batch, status, after=()):
+    """Queue the status of one batch for the src builder: sent at once, or by send()
+
+    With after, ids of files in the ftp queue, it is sent only once they are.
+    """
     xml = (f"<notification group-id='{group.id}' builder='{config.builder}'>\n"
            f"  <batch id='{batch.b_id}' status='{status}' />\n"
            "</notification>\n")
@@ -34,7 +44,9 @@ def add_batch(batch, status):
         m.write_line(msg)
         m.send()
         return
-    notifyq.add(StringIO(signed))
+    notifyq.add(StringIO(signed), after)
+    if live:
+        notifyq.flush()
 
 def send(r):
     notifyq.flush()
diff --git a/PLD_Builder/notifyq.py b/PLD_Builder/notifyq.py
index 97febad..cf5ed52 100644
--- a/PLD_Builder/notifyq.py
+++ b/PLD_Builder/notifyq.py
@@ -16,13 +16,14 @@ class Notify_Queue:
         self.requester_email = g.requester_email
         self.notify_url = config.notify_url
 
-    def add(self, file):
-        self.queue.append({'id': util.uuid(), 'text': file.read()})
+    def add(self, file, after):
+        self.queue.append({'id': util.uuid(), 'text': file.read(), 'after': after})
 
     def flush(self):
         def desc(l):
             return f"""Target: {self.notify_url}
 Id: {l['id']}
+After: {' '.join(l['after'])}
 Builder: {config.builder}
 Time: {int(time.time())}
 Requester: {self.requester_email}
@@ -38,8 +39,9 @@ END
 
 queue = Notify_Queue()
 
-def add(notify):
-    queue.add(notify)
+def add(notify, after=()):
+    """Queue a notification; file_sender holds it while a file of the ftp queue with an id in after waits"""
+    queue.add(notify, after)
 
 def flush():
     queue.flush()
diff --git a/PLD_Builder/rpm_builder.py b/PLD_Builder/rpm_builder.py
index d3d192b..c053850 100644
--- a/PLD_Builder/rpm_builder.py
+++ b/PLD_Builder/rpm_builder.py
@@ -338,7 +338,7 @@ def build_rpm(r, b):
 def handle_request(r):
     ftp.init(r)
     buildlogs.init(r)
-    build.build_all(r, build_rpm)
+    build.build_all(r, build_rpm, notify_now=True)
     report.send_report(r, is_src = False)
     ftp.flush()
     notify.send(r)
================================================================

---- gitweb:

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



More information about the pld-cvs-commit mailing list