diff options
author | Christopher Baines <mail@cbaines.net> | 2020-07-03 09:16:33 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2020-07-03 09:21:22 +0100 |
commit | 8a7e7b537eeb99e341917b14af87146cf74f96fe (patch) | |
tree | 4c54238ab888b66f3f1fe197a5ca913d2c232e26 /guix-build-coordinator/datastore | |
parent | e7e98cc7ca765a0ebaa65f9dd90fefcaeed0b308 (diff) | |
download | build-coordinator-8a7e7b537eeb99e341917b14af87146cf74f96fe.tar build-coordinator-8a7e7b537eeb99e341917b14af87146cf74f96fe.tar.gz |
Record what systems agents fetch builds for
This can then be used by allocators to avoid allocating builds to agents that
they're never going to fetch.
Diffstat (limited to 'guix-build-coordinator/datastore')
-rw-r--r-- | guix-build-coordinator/datastore/sqlite.scm | 72 |
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 |