aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--guix-build-coordinator/agent-messaging/http/server.scm10
-rw-r--r--guix-build-coordinator/coordinator.scm9
-rw-r--r--guix-build-coordinator/datastore.scm1
-rw-r--r--guix-build-coordinator/datastore/sqlite.scm39
-rw-r--r--sqitch/pg/deploy/replace_agent_status.sql7
-rw-r--r--sqitch/pg/revert/replace_agent_status.sql7
-rw-r--r--sqitch/pg/verify/replace_agent_status.sql7
-rw-r--r--sqitch/sqitch.plan1
-rw-r--r--sqitch/sqlite/deploy/replace_agent_status.sql14
-rw-r--r--sqitch/sqlite/revert/replace_agent_status.sql7
-rw-r--r--sqitch/sqlite/verify/replace_agent_status.sql7
11 files changed, 108 insertions, 1 deletions
diff --git a/guix-build-coordinator/agent-messaging/http/server.scm b/guix-build-coordinator/agent-messaging/http/server.scm
index 4741c31..75b1d77 100644
--- a/guix-build-coordinator/agent-messaging/http/server.scm
+++ b/guix-build-coordinator/agent-messaging/http/server.scm
@@ -249,7 +249,15 @@ port. Also, the port used can be changed by passing the --port option.\n"
(('PUT "agent" uuid)
(if (authenticated? uuid request)
(begin
- ;; TODO Update status
+ (let* ((json-body (json-string->scm (utf8->string body)))
+ (status (assoc-ref json-body "status"))
+ (1min-load-average (and=> (assoc-ref json-body "load_average")
+ (lambda (load-average)
+ (assoc-ref load-average 1)))))
+
+ (update-agent-status build-coordinator uuid
+ status 1min-load-average))
+
(render-json
(agent-details datastore uuid)))
(render-json
diff --git a/guix-build-coordinator/coordinator.scm b/guix-build-coordinator/coordinator.scm
index 2808426..22d97f8 100644
--- a/guix-build-coordinator/coordinator.scm
+++ b/guix-build-coordinator/coordinator.scm
@@ -79,6 +79,7 @@
new-agent
new-agent-password
set-agent-active
+ update-agent-status
fetch-builds
agent-details
trigger-build-allocation
@@ -803,6 +804,14 @@
active?)
(trigger-build-allocation coordinator))
+(define (update-agent-status coordinator agent-uuid
+ status 1min-load-average)
+ (datastore-update-agent-status
+ (build-coordinator-datastore coordinator)
+ agent-uuid
+ status
+ 1min-load-average))
+
(define (trigger-build-allocation build-coordinator)
((build-coordinator-allocator-thread build-coordinator)))
diff --git a/guix-build-coordinator/datastore.scm b/guix-build-coordinator/datastore.scm
index 68c3339..5caa8e0 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-update-agent-status)
(re-export datastore-find-agent)
(re-export datastore-find-agent-by-name)
(re-export datastore-insert-dynamic-auth-token)
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
diff --git a/sqitch/pg/deploy/replace_agent_status.sql b/sqitch/pg/deploy/replace_agent_status.sql
new file mode 100644
index 0000000..18b581b
--- /dev/null
+++ b/sqitch/pg/deploy/replace_agent_status.sql
@@ -0,0 +1,7 @@
+-- Deploy guix-build-coordinator:replace_agent_status to pg
+
+BEGIN;
+
+-- XXX Add DDLs here.
+
+COMMIT;
diff --git a/sqitch/pg/revert/replace_agent_status.sql b/sqitch/pg/revert/replace_agent_status.sql
new file mode 100644
index 0000000..edcf272
--- /dev/null
+++ b/sqitch/pg/revert/replace_agent_status.sql
@@ -0,0 +1,7 @@
+-- Revert guix-build-coordinator:replace_agent_status from pg
+
+BEGIN;
+
+-- XXX Add DDLs here.
+
+COMMIT;
diff --git a/sqitch/pg/verify/replace_agent_status.sql b/sqitch/pg/verify/replace_agent_status.sql
new file mode 100644
index 0000000..1ab295d
--- /dev/null
+++ b/sqitch/pg/verify/replace_agent_status.sql
@@ -0,0 +1,7 @@
+-- Verify guix-build-coordinator:replace_agent_status on pg
+
+BEGIN;
+
+-- XXX Add verifications here.
+
+ROLLBACK;
diff --git a/sqitch/sqitch.plan b/sqitch/sqitch.plan
index 83935e8..6ed7af9 100644
--- a/sqitch/sqitch.plan
+++ b/sqitch/sqitch.plan
@@ -41,3 +41,4 @@ recreate_unprocessed_builds_with_derived_priorities 2021-12-22T11:09:54Z Christo
derivation_output_details 2022-07-07T18:12:27Z Chris <chris@felis> # Add derivation_output_details
build_counts 2022-10-28T09:36:25Z Chris <chris@felis> # Add builds_counts
build_results_counts 2022-10-28T09:36:35Z Chris <chris@felis> # Add build_results_counts
+replace_agent_status 2023-03-22T14:17:35Z Chris <chris@felis> # Replace agent_status
diff --git a/sqitch/sqlite/deploy/replace_agent_status.sql b/sqitch/sqlite/deploy/replace_agent_status.sql
new file mode 100644
index 0000000..0d579ef
--- /dev/null
+++ b/sqitch/sqlite/deploy/replace_agent_status.sql
@@ -0,0 +1,14 @@
+-- Deploy guix-build-coordinator:replace_agent_status to sqlite
+
+BEGIN;
+
+DROP TABLE agent_status;
+
+CREATE TABLE agent_status (
+ agent_id TEXT PRIMARY KEY ASC REFERENCES agents (id),
+ timestamp DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ status TEXT NOT NULL,
+ load_average_1min INTEGER
+);
+
+COMMIT;
diff --git a/sqitch/sqlite/revert/replace_agent_status.sql b/sqitch/sqlite/revert/replace_agent_status.sql
new file mode 100644
index 0000000..d92489f
--- /dev/null
+++ b/sqitch/sqlite/revert/replace_agent_status.sql
@@ -0,0 +1,7 @@
+-- Revert guix-build-coordinator:replace_agent_status from sqlite
+
+BEGIN;
+
+-- XXX Add DDLs here.
+
+COMMIT;
diff --git a/sqitch/sqlite/verify/replace_agent_status.sql b/sqitch/sqlite/verify/replace_agent_status.sql
new file mode 100644
index 0000000..0526dd0
--- /dev/null
+++ b/sqitch/sqlite/verify/replace_agent_status.sql
@@ -0,0 +1,7 @@
+-- Verify guix-build-coordinator:replace_agent_status on sqlite
+
+BEGIN;
+
+-- XXX Add verifications here.
+
+ROLLBACK;