From 804165f14ccf613b7d76b2bda83fbfd49019f7e4 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Tue, 21 Mar 2023 13:54:33 +0000 Subject: 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. --- guix-build-coordinator/client-communication.scm | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'guix-build-coordinator/client-communication.scm') 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 -- cgit v1.2.3