aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2023-03-22 15:37:05 +0000
committerChristopher Baines <mail@cbaines.net>2023-03-22 15:56:13 +0000
commit13e283ddc2e9b0a62f9bbd9b67fbd8fbec393629 (patch)
tree0397696f06905186062ed116e0b84647afa18ed6
parent51c318b99b7ff2203be7924fc5ff626a113f252c (diff)
downloadbuild-coordinator-13e283ddc2e9b0a62f9bbd9b67fbd8fbec393629.tar
build-coordinator-13e283ddc2e9b0a62f9bbd9b67fbd8fbec393629.tar.gz
Include the last agent statuses in the overall status
-rw-r--r--guix-build-coordinator/client-communication.scm17
-rw-r--r--guix-build-coordinator/datastore.scm1
-rw-r--r--guix-build-coordinator/datastore/sqlite.scm28
3 files changed, 40 insertions, 6 deletions
diff --git a/guix-build-coordinator/client-communication.scm b/guix-build-coordinator/client-communication.scm
index 5d443d8..2d8d4bc 100644
--- a/guix-build-coordinator/client-communication.scm
+++ b/guix-build-coordinator/client-communication.scm
@@ -504,12 +504,17 @@
(agents . ,(list->vector
(map
(lambda (agent-details)
- `(,@agent-details
- (builds
- . ,(list->vector
- (datastore-list-agent-builds
- datastore
- (assq-ref agent-details 'uuid))))))
+ (let ((agent-id
+ (assq-ref agent-details 'uuid)))
+ `(,@agent-details
+ (last_status_update
+ . ,(datastore-find-agent-status datastore
+ agent-id))
+ (builds
+ . ,(list->vector
+ (datastore-list-agent-builds
+ datastore
+ (assq-ref agent-details 'uuid)))))))
(datastore-list-agents datastore)))))))))
(('GET "events")
(list (build-response
diff --git a/guix-build-coordinator/datastore.scm b/guix-build-coordinator/datastore.scm
index 5caa8e0..d9cc772 100644
--- a/guix-build-coordinator/datastore.scm
+++ b/guix-build-coordinator/datastore.scm
@@ -23,6 +23,7 @@
(re-export datastore-new-agent)
(re-export datastore-list-agents)
(re-export datastore-set-agent-active)
+(re-export datastore-find-agent-status)
(re-export datastore-update-agent-status)
(re-export datastore-find-agent)
(re-export datastore-find-agent-by-name)
diff --git a/guix-build-coordinator/datastore/sqlite.scm b/guix-build-coordinator/datastore/sqlite.scm
index c7c4617..ba4a6d4 100644
--- a/guix-build-coordinator/datastore/sqlite.scm
+++ b/guix-build-coordinator/datastore/sqlite.scm
@@ -56,6 +56,7 @@
datastore-new-agent
datastore-list-agents
datastore-set-agent-active
+ datastore-find-agent-status
datastore-update-agent-status
datastore-find-agent
datastore-find-agent-by-name
@@ -676,6 +677,33 @@ UPDATE agents SET active = :active WHERE id = :uuid"
(sqlite-finalize statement))))
active?)
+(define-method (datastore-find-agent-status
+ (datastore <sqlite-datastore>)
+ agent-id)
+ (call-with-worker-thread
+ (slot-ref datastore 'worker-reader-thread-channel)
+ (lambda (db)
+ (let ((statement
+ (sqlite-prepare
+ db
+ "
+SELECT status, load_average_1min
+FROM agent_status
+WHERE agent_id = :agent_id"
+ #:cache? #t)))
+
+ (sqlite-bind-arguments
+ statement
+ #:agent_id agent-id)
+
+ (match (sqlite-step statement)
+ (#(status 1min_load_average)
+ (sqlite-reset statement)
+
+ `((status . ,status)
+ (1min_load_average . ,1min_load_average)))
+ (_ #f))))))
+
(define-method (datastore-update-agent-status
(datastore <sqlite-datastore>)
agent-uuid