From f9bd2f047e295beb8252af8ae1eafaa43b70aa2a Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Wed, 22 Mar 2023 15:16:44 +0000 Subject: Implement and extend the agent status functionality Previously, updating the status was used by the agent just to get back the list of builds it was already allocated. Now the status sent is actually stored, along with the 1min load average. --- guix-build-coordinator/datastore/sqlite.scm | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'guix-build-coordinator/datastore/sqlite.scm') diff --git a/guix-build-coordinator/datastore/sqlite.scm b/guix-build-coordinator/datastore/sqlite.scm index 07b7aed..c7c4617 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-update-agent-status datastore-find-agent datastore-find-agent-by-name datastore-insert-dynamic-auth-token @@ -675,6 +676,44 @@ UPDATE agents SET active = :active WHERE id = :uuid" (sqlite-finalize statement)))) active?) +(define-method (datastore-update-agent-status + (datastore ) + agent-uuid + status + 1min-load-average) + (call-with-worker-thread + (slot-ref datastore 'worker-writer-thread-channel) + (lambda (db) + (let ((statement + (sqlite-prepare + db + " +DELETE FROM agent_status WHERE agent_id = :uuid" + #:cache? #t))) + + (sqlite-bind-arguments statement + #:uuid agent-uuid) + (sqlite-step statement) + (sqlite-reset statement)) + + (let ((statement + (sqlite-prepare + db + " +INSERT INTO agent_status (agent_id, status, load_average_1min) + VALUES (:uuid, :status, :load)" + #:cache? #t))) + + (sqlite-bind-arguments statement + #:uuid agent-uuid + #:status status + #:load 1min-load-average) + + (sqlite-step statement) + (sqlite-reset statement)))) + + #t) + (define-method (datastore-new-agent-password (datastore ) agent-uuid -- cgit v1.2.3