Subject: [PATCH Cuirass 13/13] base: Add support for forge notification in jobset-monitor.

From: Romain GARBAGE <[email-masked]>
Date: Tue, 11 Mar 2025 11:34:38 +0100

* src/cuirass/base.scm (jobset-monitor, spawn-jobset-monitor): Add support for forge notification.
(jobset-registry): Transmit the communication channel for event-log to jobset-monitors.
---
 src/cuirass/base.scm | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/src/cuirass/base.scm b/src/cuirass/base.scm
index c3a0fb6..d62960e 100644
--- a/src/cuirass/base.scm
+++ b/src/cuirass/base.scm
@@ -25,6 +25,7 @@
   #:use-module (fibers channels)
   #:use-module (cuirass logging)
   #:use-module (cuirass database)
+  #:use-module (cuirass forges notification)
   #:autoload   (cuirass metrics) (db-remove-specification-metrics)
   #:use-module (cuirass remote)
   #:use-module (cuirass specification)
@@ -123,6 +124,10 @@
 ;;;    such as evaluation triggers that can come, for example, from the
 ;;;    /jobset/NAME/hook/evaluate HTTP endpoint.
 ;;;
+;;;  - Each jobset might also be associated with a "forge notifier", started by
+;;;    the "monitor": when applicable, it is responsible for communicating with
+;;;    external forges using the correspondent API.
+;;;
 ;;;  - The "jobset" registry is a directory that maps jobset names to their
 ;;;    monitor.
 ;;;
@@ -874,6 +879,14 @@ notification subscriptions."
                          update-service evaluator event-log)
   (define name (specification-name spec))
 
+  (define forge-notifier (and (assoc-ref (specification-properties spec)
+                                         'forge-type)
+                              (spawn-forge-notification-service spec)))
+
+  (when forge-notifier
+    (put-message event-log
+                 `(subscribe ,forge-notifier)))
+
   (lambda ()
     (log-info "starting monitor for spec '~a'" name)
     (let loop ((spec spec)
@@ -954,6 +967,9 @@ notification subscriptions."
                  (loop spec last-updates))
                 ('terminate
                  (log-info "terminating monitor of jobset '~a'" name)
+                 (when forge-notifier
+                   (put-message event-log
+                                `(unsubscribe ,forge-notifier)))
                  #t)
                 (message
                  (log-warning "jobset '~a' got bogus message: ~s"
@@ -976,6 +992,9 @@ notification subscriptions."
              (loop spec last-updates))
             ('terminate
              (log-info "terminating monitor of inactive jobset '~a'" name)
+             (when forge-notifier
+               (put-message event-log
+                            `(unsubscribe ,forge-notifier)))
              #t)
             (message
              (log-warning "inactive jobset '~a' got unexpected message: ~s"
-- 
2.48.1