diff options
author | Christopher Baines <mail@cbaines.net> | 2022-10-09 11:53:01 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2022-10-09 11:53:01 +0100 |
commit | 7912b9bfe3d40f6f5393d764c6a18cbdb4b6880e (patch) | |
tree | ff2cb0a2fb18f99a5bcc0336b5f9dd70b093e4b4 /guix-build-coordinator/datastore/sqlite.scm | |
parent | ed52f0bb40f5f2d771740c923540c0d8f6d3f1f3 (diff) | |
download | build-coordinator-7912b9bfe3d40f6f5393d764c6a18cbdb4b6880e.tar build-coordinator-7912b9bfe3d40f6f5393d764c6a18cbdb4b6880e.tar.gz |
Improve listing agent build allocation plans
Diffstat (limited to 'guix-build-coordinator/datastore/sqlite.scm')
-rw-r--r-- | guix-build-coordinator/datastore/sqlite.scm | 66 |
1 files changed, 42 insertions, 24 deletions
diff --git a/guix-build-coordinator/datastore/sqlite.scm b/guix-build-coordinator/datastore/sqlite.scm index 5bdbc6f..ff30c0b 100644 --- a/guix-build-coordinator/datastore/sqlite.scm +++ b/guix-build-coordinator/datastore/sqlite.scm @@ -2,6 +2,7 @@ #:use-module (oop goops) #:use-module (srfi srfi-1) #:use-module (srfi srfi-19) + #:use-module (srfi srfi-43) #:use-module (srfi srfi-71) #:use-module (ice-9 match) #:use-module (ice-9 format) @@ -3256,16 +3257,18 @@ WHERE agent_id = :agent_id" (define-method (datastore-list-allocation-plan-builds (datastore <sqlite-datastore>) - agent-id - limit) - (call-with-worker-thread - (slot-ref datastore 'worker-reader-thread-channel) - (lambda (db) - (let ((statement - (sqlite-prepare - db - ;; This needs to guard against the plan being out of date - " + . + rest) + (apply + (lambda* (agent-id #:key limit) + (call-with-worker-thread + (slot-ref datastore 'worker-reader-thread-channel) + (lambda (db) + (let ((statement + (sqlite-prepare + db + (string-append + " SELECT builds.uuid, derivations.name FROM builds INNER JOIN derivations @@ -3275,24 +3278,39 @@ INNER JOIN build_allocation_plan WHERE build_allocation_plan.agent_id = :agent_id AND builds.processed = 0 AND builds.id NOT IN (SELECT build_id FROM allocated_builds) -ORDER BY build_allocation_plan.ordering ASC +ORDER BY build_allocation_plan.ordering ASC" + (if limit + " LIMIT :limit" - #:cache? #t))) + "")) + #:cache? #t))) - (sqlite-bind-arguments - statement - #:agent_id agent-id - #:limit limit) + (apply sqlite-bind-arguments + statement + #:agent_id agent-id + (if limit + (list #:limit limit) + '())) - (let ((builds (sqlite-map - (match-lambda - (#(uuid derivation_name) - `((uuid . ,uuid) - (derivation-name . ,derivation_name)))) - statement))) - (sqlite-reset statement) + (let ((builds (sqlite-map + (match-lambda + (#(uuid derivation_name) + `((uuid . ,uuid) + (derivation-name . ,derivation_name) + (tags . ,(vector-map + (lambda (_ tag) + (match tag + ((key . value) + `((key . ,key) + (value . ,value))))) + (datastore-fetch-build-tags + datastore + uuid)))))) + statement))) + (sqlite-reset statement) - builds))))) + builds))))) + rest)) (define-method (datastore-list-agent-builds (datastore <sqlite-datastore>) |