diff options
author | Christopher Baines <mail@cbaines.net> | 2023-04-03 13:49:03 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2023-04-03 13:49:03 +0100 |
commit | 60fac8121cc668a01f22a569059aa00d476db566 (patch) | |
tree | fa52a18d67a0d97345c4918796f63674b522a97d /guix-build-coordinator/coordinator.scm | |
parent | 9fc74074e6e81aa6c9acd368bc4a6ee5eb9b45d2 (diff) | |
download | build-coordinator-60fac8121cc668a01f22a569059aa00d476db566.tar build-coordinator-60fac8121cc668a01f22a569059aa00d476db566.tar.gz |
Improve event/state id support for events
Support the Last-Event-ID header in the events endpoint, and include the event
id's in the responses.
Diffstat (limited to 'guix-build-coordinator/coordinator.scm')
-rw-r--r-- | guix-build-coordinator/coordinator.scm | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/guix-build-coordinator/coordinator.scm b/guix-build-coordinator/coordinator.scm index b022c76..b19d278 100644 --- a/guix-build-coordinator/coordinator.scm +++ b/guix-build-coordinator/coordinator.scm @@ -178,7 +178,7 @@ (when (not (= event-state-id index-state-id)) (error "listener behind")) - (callback event-name data)))) + (callback event-state-id event-name data)))) (map (lambda (i) (modulo i buffer-size)) (iota event-count-to-send @@ -226,10 +226,20 @@ (lambda () (while #t (match (get-message submission-channel) - (('new-listener callback after-state-id + (('new-listener callback requested-after-state-id listening-finished-channel) - (let ((listener-channel (make-channel))) + (let ((listener-channel (make-channel)) + (after-state-id + (match (atomic-box-ref + current-state-id-and-event-buffer-index-box) + ((current-state-id . event-buffer-index) + (if requested-after-state-id + (if (> requested-after-state-id + current-state-id) + current-state-id + requested-after-state-id) + current-state-id))))) (atomic-box-set! listener-channels-box (vhash-consq listener-channel @@ -237,11 +247,7 @@ (atomic-box-ref listener-channels-box))) (spawn-fiber-for-listener callback - (or after-state-id - (match (atomic-box-ref - current-state-id-and-event-buffer-index-box) - ((current-state-id . event-buffer-index) - current-state-id))) + after-state-id submission-channel listener-channel listening-finished-channel))) |