aboutsummaryrefslogtreecommitdiff
path: root/guix-build-coordinator/client-communication.scm
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2023-03-21 13:54:33 +0000
committerChristopher Baines <mail@cbaines.net>2023-03-21 13:54:33 +0000
commit804165f14ccf613b7d76b2bda83fbfd49019f7e4 (patch)
tree89f97ec0dbb94ab348ba567bec5ccc4ae65486fe /guix-build-coordinator/client-communication.scm
parent3a11b724f62cc863e8e5b09faf2171ff41b1de18 (diff)
downloadbuild-coordinator-804165f14ccf613b7d76b2bda83fbfd49019f7e4.tar
build-coordinator-804165f14ccf613b7d76b2bda83fbfd49019f7e4.tar.gz
Get the state to use with events from the database
I was thinking of storing/maintaining this in memory, but that's not great as there's a high chance that some coding issue means it will diverge from the database. Instead, pull the state from the database, and try to return it with an appropriate state_id value. I'm not sure I've got this exactly right, maybe some of the event stuff will need bringing in to the transactions in the coordinator, but this should be OK to start off with.
Diffstat (limited to 'guix-build-coordinator/client-communication.scm')
-rw-r--r--guix-build-coordinator/client-communication.scm18
1 files changed, 18 insertions, 0 deletions
diff --git a/guix-build-coordinator/client-communication.scm b/guix-build-coordinator/client-communication.scm
index 698a62e..5d443d8 100644
--- a/guix-build-coordinator/client-communication.scm
+++ b/guix-build-coordinator/client-communication.scm
@@ -493,6 +493,24 @@
'()))
#:threshold 10)))
(render-json submit-build-result))))
+ (('GET "state")
+ ;; Use a write transaction here to get a snapshot of the state plus the
+ ;; state-id
+ (render-json
+ (datastore-call-with-transaction
+ datastore
+ (lambda (_)
+ `((state_id . ,(build-coordinator-get-state-id build-coordinator))
+ (agents . ,(list->vector
+ (map
+ (lambda (agent-details)
+ `(,@agent-details
+ (builds
+ . ,(list->vector
+ (datastore-list-agent-builds
+ datastore
+ (assq-ref agent-details 'uuid))))))
+ (datastore-list-agents datastore)))))))))
(('GET "events")
(list (build-response
#:code 200