[projects/pld-builder.new] notify: one notification per batch
arekm
arekm at pld-linux.org
Thu Nov 12 00:29:51 CET 2026
commit 22f08de1be4dee06406ab0917ee18df3d4da9cfa
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Wed Nov 11 23:12:03 2026 +0100
notify: one notification per batch
A builder kept one notification for the whole request and added each
batch status to it. Each status is now signed and queued as its own
notification, still sent when the request ends, so the src builder
ends up with the same statuses. This lets a later change send a status
as soon as it is known.
notifyq.flush() now forgets what it wrote, so a second flush cannot
write the same notifications again.
PLD_Builder/notify.py | 61 ++++++++++++++++++++------------------------------
PLD_Builder/notifyq.py | 9 ++++----
2 files changed, 29 insertions(+), 41 deletions(-)
---
diff --git a/PLD_Builder/notify.py b/PLD_Builder/notify.py
index 7df3e34..430209e 100644
--- a/PLD_Builder/notify.py
+++ b/PLD_Builder/notify.py
@@ -9,45 +9,32 @@ import notifyq
import util
from config import config
+# the request the statuses are of
+group = None
-class Notifier:
- def __init__(self, g):
- self.xml = StringIO()
- self.xml.write(f"<notification group-id='{g.id}' builder='{config.builder}'>\n")
-
- def send(self, r):
- sio = StringIO()
- self.xml.write("</notification>\n")
- self.xml.seek(0)
- try:
- sio.write(util.to_str(gpg.sign(self.xml.read())))
- except (log.Panic, OSError) as e:
- # raising here would leave a finished build queued on a bin
- # builder and rebuild it on every run until gpg works again
- msg = f"notification for {r.id} not sent: signing failed: {e}"
- log.alert(msg)
- m = mailer.Message()
- m.set_headers(to = config.admin_email, subject = f"[{config.builder}] notification not sent")
- m.write_line(msg)
- m.send()
- return
- self.xml = None
- sio.seek(0)
- notifyq.init(r)
- notifyq.add(sio)
- notifyq.flush()
-
- def add_batch(self, b, s):
- self.xml.write(f" <batch id='{b.b_id}' status='{s}' />\n")
-
-n = None
-
-def begin(group):
- global n
- n = Notifier(group)
+def begin(g):
+ global group
+ group = g
+ notifyq.init(g)
def add_batch(batch, status):
- n.add_batch(batch, status)
+ """Queue the status of one batch for the src builder; send() sends what is queued"""
+ xml = (f"<notification group-id='{group.id}' builder='{config.builder}'>\n"
+ f" <batch id='{batch.b_id}' status='{status}' />\n"
+ "</notification>\n")
+ try:
+ signed = util.to_str(gpg.sign(xml))
+ except (log.Panic, OSError) as e:
+ # raising here would leave a finished build queued on a bin
+ # builder and rebuild it on every run until gpg works again
+ msg = f"notification for {group.id} not sent: signing failed: {e}"
+ log.alert(msg)
+ m = mailer.Message()
+ m.set_headers(to = config.admin_email, subject = f"[{config.builder}] notification not sent")
+ m.write_line(msg)
+ m.send()
+ return
+ notifyq.add(StringIO(signed))
def send(r):
- n.send(r)
+ notifyq.flush()
diff --git a/PLD_Builder/notifyq.py b/PLD_Builder/notifyq.py
index 0867f40..97febad 100644
--- a/PLD_Builder/notifyq.py
+++ b/PLD_Builder/notifyq.py
@@ -17,10 +17,7 @@ class Notify_Queue:
self.notify_url = config.notify_url
def add(self, file):
- id = util.uuid()
- with open(path.notify_queue_dir + '/' + id, 'w') as f:
- f.write(file.read())
- self.queue.append({'id': id})
+ self.queue.append({'id': util.uuid(), 'text': file.read()})
def flush(self):
def desc(l):
@@ -32,8 +29,12 @@ Requester: {self.requester_email}
END
"""
+ # nothing reaches the spool before this: a request that stops halfway leaves no files behind
for l in self.queue:
+ with open(path.notify_queue_dir + '/' + l['id'], 'w') as f:
+ f.write(l['text'])
util.write_atomic(path.notify_queue_dir + '/' + l['id'] + ".desc", desc(l))
+ self.queue = []
queue = Notify_Queue()
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/projects/pld-builder.new.git/commitdiff/2cf988b75f72cba070da99d03d3c3e709f5166bc
More information about the pld-cvs-commit
mailing list