diff options
author | Christopher Baines <mail@cbaines.net> | 2023-03-22 15:16:44 +0000 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2023-03-22 15:55:34 +0000 |
commit | f9bd2f047e295beb8252af8ae1eafaa43b70aa2a (patch) | |
tree | 6a4c1fb70f64e1fd2712f16cad0164476500372b /guix-build-coordinator/datastore/sqlite.scm | |
parent | 7ee1cc4924813b1ae59958f29cf6dd5e22c3e673 (diff) | |
download | build-coordinator-f9bd2f047e295beb8252af8ae1eafaa43b70aa2a.tar build-coordinator-f9bd2f047e295beb8252af8ae1eafaa43b70aa2a.tar.gz |
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.
Diffstat (limited to 'guix-build-coordinator/datastore/sqlite.scm')
-rw-r--r-- | guix-build-coordinator/datastore/sqlite.scm | 39 |
1 files changed, 39 insertions, 0 deletions
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 <sqlite-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 <sqlite-datastore>) agent-uuid |