aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--guix-build-coordinator/datastore.scm5
-rw-r--r--guix-build-coordinator/datastore/sqlite.scm111
2 files changed, 116 insertions, 0 deletions
diff --git a/guix-build-coordinator/datastore.scm b/guix-build-coordinator/datastore.scm
index 7fc16df..389bc7c 100644
--- a/guix-build-coordinator/datastore.scm
+++ b/guix-build-coordinator/datastore.scm
@@ -13,7 +13,9 @@
(re-export datastore-new-agent)
(re-export datastore-list-agents)
(re-export datastore-find-agent)
+(re-export datastore-count-build-results)
(re-export datastore-store-build-result)
+(re-export datastore-count-setup-failures)
(re-export datastore-fetch-setup-failures)
(re-export datastore-list-build-outputs)
(re-export datastore-list-related-derivations-with-no-build)
@@ -22,6 +24,7 @@
(re-export datastore-list-setup-failure-missing-inputs)
(re-export datastore-new-agent-password)
(re-export datastore-agent-password-exists?)
+(re-export datastore-count-builds)
(re-export datastore-find-build)
(re-export datastore-list-builds-for-derivation)
(re-export datastore-list-unprocessed-builds)
@@ -31,7 +34,9 @@
(re-export datastore-find-derivation-inputs)
(re-export datastore-list-builds-for-output)
(re-export datastore-agent-for-build)
+(re-export datastore-count-build-allocation-plan-entries)
(re-export datastore-replace-build-allocation-plan)
+(re-export datastore-count-allocated-builds)
(re-export datastore-allocate-builds-to-agent)
(re-export datastore-list-allocation-plan-builds)
diff --git a/guix-build-coordinator/datastore/sqlite.scm b/guix-build-coordinator/datastore/sqlite.scm
index 2416b70..e10b04e 100644
--- a/guix-build-coordinator/datastore/sqlite.scm
+++ b/guix-build-coordinator/datastore/sqlite.scm
@@ -13,13 +13,16 @@
datastore-store-derivation
datastore-list-related-derivations-with-no-build
datastore-store-build
+ datastore-count-builds
datastore-find-build
datastore-list-builds-for-derivation
+ datastore-count-build-results
datastore-store-build-result
datastore-list-build-outputs
datastore-new-agent
datastore-list-agents
datastore-find-agent
+ datastore-count-setup-failures
datastore-fetch-setup-failures
datastore-store-setup-failure
datastore-store-setup-failure/missing-inputs
@@ -33,7 +36,9 @@
datastore-list-unprocessed-builds
datastore-list-agent-builds
datastore-agent-for-build
+ datastore-count-build-allocation-plan-entries
datastore-replace-build-allocation-plan
+ datastore-count-allocated-builds
datastore-allocate-builds-to-agent
datastore-list-allocation-plan-builds))
@@ -240,6 +245,27 @@ WHERE name != :derivation
(sqlite-exec db "COMMIT TRANSACTION;")))))
#t)
+(define-method (datastore-count-build-results
+ (datastore <sqlite-datastore>))
+ (call-with-worker-thread
+ (slot-ref datastore 'worker-thread-channel)
+ (lambda (db)
+ (let ((statement
+ (sqlite-prepare
+ db
+ "
+SELECT agent_id, result, COUNT(*) FROM build_results GROUP BY agent_id, result")))
+
+ (let ((result
+ (sqlite-map
+ (match-lambda
+ (#(agent_id result count)
+ (cons (list agent_id result) count)))
+ statement)))
+ (sqlite-reset statement)
+
+ result)))))
+
(define-method (datastore-store-build-result
(datastore <sqlite-datastore>)
build-id
@@ -456,6 +482,24 @@ WHERE setup_failure_id = :id")))
agent-id
failure-reason))))
+(define-method (datastore-count-builds
+ (datastore <sqlite-datastore>))
+ (call-with-worker-thread
+ (slot-ref datastore 'worker-thread-channel)
+ (lambda (db)
+ (let ((statement
+ (sqlite-prepare
+ db
+ "
+SELECT COUNT(*) FROM builds")))
+
+ (let ((result
+ (match (sqlite-step statement)
+ (#(count) count))))
+ (sqlite-reset statement)
+
+ result)))))
+
(define-method (datastore-find-build
(datastore <sqlite-datastore>)
uuid)
@@ -554,6 +598,29 @@ SELECT uuid FROM builds WHERE derivation_name = :derivation")))
#t)
+(define-method (datastore-count-setup-failures
+ (datastore <sqlite-datastore>))
+ (call-with-worker-thread
+ (slot-ref datastore 'worker-thread-channel)
+ (lambda (db)
+ (let ((statement
+ (sqlite-prepare
+ db
+ "
+SELECT agent_id, failure_reason, COUNT(*)
+FROM setup_failures
+GROUP BY agent_id, failure_reason")))
+
+ (let ((result
+ (sqlite-map
+ (match-lambda
+ (#(agent_id failure_reason count)
+ (cons (list agent_id failure_reason) count)))
+ statement)))
+ (sqlite-reset statement)
+
+ result)))))
+
(define-method (datastore-fetch-setup-failures
(datastore <sqlite-datastore>))
(call-with-worker-thread
@@ -607,6 +674,29 @@ SELECT uuid, derivation_name, priority FROM builds WHERE processed = 0")))
builds)))))
+(define-method (datastore-count-build-allocation-plan-entries
+ (datastore <sqlite-datastore>))
+ (call-with-worker-thread
+ (slot-ref datastore 'worker-thread-channel)
+ (lambda (db)
+ (let ((statement
+ (sqlite-prepare
+ db
+ "
+SELECT agent_id, COUNT(*)
+FROM build_allocation_plan
+GROUP BY agent_id")))
+
+ (let ((result
+ (sqlite-map
+ (match-lambda
+ (#(agent_id count)
+ (cons agent_id count)))
+ statement)))
+ (sqlite-reset statement)
+
+ result)))))
+
(define-method (datastore-replace-build-allocation-plan
(datastore <sqlite-datastore>)
planned-builds)
@@ -651,6 +741,27 @@ INSERT INTO build_allocation_plan (build_id, agent_id, ordering) VALUES "
(sqlite-exec db "COMMIT TRANSACTION;")))))
#t)
+(define-method (datastore-count-allocated-builds
+ (datastore <sqlite-datastore>))
+ (call-with-worker-thread
+ (slot-ref datastore 'worker-thread-channel)
+ (lambda (db)
+ (let ((statement
+ (sqlite-prepare
+ db
+ "
+SELECT agent_id, COUNT(*) FROM allocated_builds GROUP BY agent_id")))
+
+ (let ((result
+ (sqlite-map
+ (match-lambda
+ (#(agent_id count)
+ (cons agent_id count)))
+ statement)))
+ (sqlite-reset statement)
+
+ result)))))
+
(define-method (datastore-allocate-builds-to-agent
(datastore <sqlite-datastore>)
agent-id