diff options
author | Christopher Baines <mail@cbaines.net> | 2023-03-21 12:42:25 +0000 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2023-03-21 12:59:43 +0000 |
commit | 36477113fd935b108b64477d0e1e063111eae3da (patch) | |
tree | 11883f944234726f8b5ce541b9bf7727f10da56a /guix-build-coordinator/client-communication.scm | |
parent | 76110df5f07cf4d895ff96a2ef01187f2bb5789b (diff) | |
download | build-coordinator-36477113fd935b108b64477d0e1e063111eae3da.tar build-coordinator-36477113fd935b108b64477d0e1e063111eae3da.tar.gz |
Add initial support for listening for events
This uses server sent events, and requires Guile Fibers with support for
chunked transport encoding responses.
Diffstat (limited to 'guix-build-coordinator/client-communication.scm')
-rw-r--r-- | guix-build-coordinator/client-communication.scm | 19 |
1 files changed, 19 insertions, 0 deletions
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" |