From 36477113fd935b108b64477d0e1e063111eae3da Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Tue, 21 Mar 2023 12:42:25 +0000 Subject: Add initial support for listening for events This uses server sent events, and requires Guile Fibers with support for chunked transport encoding responses. --- guix-build-coordinator/client-communication.scm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/guix-build-coordinator/client-communication.scm b/guix-build-coordinator/client-communication.scm index d9f2c88..937b679 100644 --- a/guix-build-coordinator/client-communication.scm +++ b/guix-build-coordinator/client-communication.scm @@ -493,6 +493,25 @@ '())) #:threshold 10))) (render-json submit-build-result)))) + (('GET "events") + (list (build-response + #:code 200 + #:headers '((content-type . (text/event-stream)))) + (lambda (port) + (build-coordinator-listen-for-events + build-coordinator + (lambda (event-name data) + (display + (simple-format #f "event: ~A\ndata: ~A\n\n" + event-name + (scm->json-string data)) + port) + (force-output port) + ;; TODO because the chunked output port doesn't call + ;; force-output on the underlying port, do that here. We + ;; want this event to be sent now, rather than when some + ;; buffer fills up. + (force-output (request-port request))))))) (_ (render-json "not-found" -- cgit v1.2.3