aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2020-04-11 11:34:48 +0100
committerChristopher Baines <mail@cbaines.net>2020-04-11 11:34:48 +0100
commitcb833e6ce09b2a974af714a149a96d979ca631de (patch)
tree74ec09efc4bdd679c2afac31743f91c4748eb443
parent85228c9a4b56135e77505f0e367c3392fa759081 (diff)
downloadbuild-coordinator-cb833e6ce09b2a974af714a149a96d979ca631de.tar
build-coordinator-cb833e6ce09b2a974af714a149a96d979ca631de.tar.gz
Support listing builds allocated for an agent
-rw-r--r--guix-build-coordinator/datastore.scm1
-rw-r--r--guix-build-coordinator/datastore/abstract.scm2
-rw-r--r--guix-build-coordinator/datastore/sqlite.scm32
3 files changed, 35 insertions, 0 deletions
diff --git a/guix-build-coordinator/datastore.scm b/guix-build-coordinator/datastore.scm
index 04ef0d9..7503110 100644
--- a/guix-build-coordinator/datastore.scm
+++ b/guix-build-coordinator/datastore.scm
@@ -12,6 +12,7 @@
datastore-new-agent-password
datastore-agent-password-exists?
datastore-list-unprocessed-builds
+ datastore-list-agent-builds
datastore-replace-build-allocation-plan
datastore-allocate-builds-to-agent
datastore-list-allocation-plan-builds)
diff --git a/guix-build-coordinator/datastore/abstract.scm b/guix-build-coordinator/datastore/abstract.scm
index 9d4e7b1..78e48d7 100644
--- a/guix-build-coordinator/datastore/abstract.scm
+++ b/guix-build-coordinator/datastore/abstract.scm
@@ -8,6 +8,7 @@
datastore-find-agent
datastore-new-agent
datastore-new-agent-password
+ datastore-list-agent-builds
datastore-agent-password-exists?
datastore-allocate-builds-to-agent
datastore-list-allocation-plan-builds))
@@ -23,6 +24,7 @@
(define-generic datastore-update)
(define-generic datastore-agent-password-exists?)
(define-generic datastore-agent-list-unprocessed-builds)
+(define-generic datastore-list-agent-builds)
(define-generic datastore-agent-replace-build-allocation-plan)
(define-generic datastore-allocate-builds-to-agent)
(define-generic datastore-list-allocation-plan-builds)
diff --git a/guix-build-coordinator/datastore/sqlite.scm b/guix-build-coordinator/datastore/sqlite.scm
index 3ee3f6c..befa560 100644
--- a/guix-build-coordinator/datastore/sqlite.scm
+++ b/guix-build-coordinator/datastore/sqlite.scm
@@ -18,6 +18,7 @@
datastore-new-agent-password
datastore-agent-password-exists?
datastore-list-unprocessed-builds
+ datastore-list-agent-builds
datastore-replace-build-allocation-plan
datastore-allocate-builds-to-agent
datastore-list-allocation-plan-builds))
@@ -310,6 +311,37 @@ LIMIT :limit")))
builds)))))
+(define-method (datastore-list-agent-builds
+ (datastore <sqlite-datastore>)
+ agent-id)
+ (call-with-worker-thread
+ (slot-ref datastore 'worker-thread-channel)
+ (lambda (db)
+ (let ((statement
+ (sqlite-prepare
+ db
+ "
+SELECT builds.uuid, builds.derivation_name, builds.priority
+FROM builds
+INNER JOIN allocated_builds
+ ON builds.uuid = allocated_builds.build_id
+WHERE allocated_builds.agent_id = :agent_id")))
+
+ (sqlite-bind-arguments
+ statement
+ #:agent_id agent-id)
+
+ (let ((builds (sqlite-map
+ (match-lambda
+ (#(uuid derivation_name priority)
+ `((uuid . ,uuid)
+ (derivation-name . ,derivation_name)
+ (priority . ,priority))))
+ statement)))
+ (sqlite-reset statement)
+
+ builds)))))
+
(define (db-open database)
(define flags
(list SQLITE_OPEN_READWRITE