aboutsummaryrefslogtreecommitdiff
path: root/guix-build-coordinator/datastore/sqlite.scm
diff options
context:
space:
mode:
Diffstat (limited to 'guix-build-coordinator/datastore/sqlite.scm')
-rw-r--r--guix-build-coordinator/datastore/sqlite.scm72
1 files changed, 72 insertions, 0 deletions
diff --git a/guix-build-coordinator/datastore/sqlite.scm b/guix-build-coordinator/datastore/sqlite.scm
index 9c9172a..c1a0836 100644
--- a/guix-build-coordinator/datastore/sqlite.scm
+++ b/guix-build-coordinator/datastore/sqlite.scm
@@ -55,6 +55,8 @@
datastore-count-build-allocation-plan-entries
datastore-replace-build-allocation-plan
datastore-count-allocated-builds
+ datastore-agent-requested-systems
+ datastore-update-agent-requested-systems
datastore-allocate-builds-to-agent
datastore-list-allocation-plan-builds))
@@ -1371,6 +1373,76 @@ SELECT agent_id, COUNT(*) FROM allocated_builds GROUP BY agent_id")))
result)))))
+(define-method (datastore-agent-requested-systems
+ (datastore <sqlite-datastore>)
+ agent-id)
+ (call-with-worker-thread
+ (slot-ref datastore 'worker-reader-thread-channel)
+ (lambda (db)
+ (let ((statement
+ (sqlite-prepare
+ db
+ "
+SELECT system
+FROM build_allocation_agent_requested_systems
+WHERE agent_id = :agent_id
+ORDER BY system ASC")))
+
+ (sqlite-bind-arguments
+ statement
+ #:agent_id agent-id)
+
+ (let ((result
+ (sqlite-map
+ (match-lambda (#(system) system))
+ statement)))
+ (sqlite-reset statement)
+
+ result)))))
+
+(define-method (datastore-update-agent-requested-systems
+ (datastore <sqlite-datastore>)
+ agent-id
+ systems)
+ (define update-not-needed?
+ (equal? (sort systems
+ string<?)
+ (datastore-agent-requested-systems
+ datastore
+ agent-id)))
+
+ (if update-not-needed?
+ #f
+ (datastore-call-with-transaction
+ datastore
+ (lambda (db)
+ (sqlite-exec
+ db
+ (simple-format
+ #f
+ "
+DELETE FROM build_allocation_agent_requested_systems
+WHERE agent_id = '~A'"
+ agent-id))
+
+ (sqlite-exec
+ db
+ (string-append
+ "
+INSERT INTO build_allocation_agent_requested_systems (agent_id, system) VALUES "
+ (string-join
+ (map (lambda (system)
+ (simple-format
+ #f
+ "('~A', '~A')"
+ agent-id
+ system))
+ systems)
+ ", ")
+ ";"))
+
+ #t))))
+
(define-method (datastore-allocate-builds-to-agent
(datastore <sqlite-datastore>)
agent-id