From f1e444babead95908ea269d08d5902097663ca4b Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Tue, 1 Jul 2025 13:07:44 +0100 Subject: [PATCH] Process queued build events in parallel --- guix-data-service/web/server.scm | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/guix-data-service/web/server.scm b/guix-data-service/web/server.scm index cced889..d1b1284 100644 --- a/guix-data-service/web/server.scm +++ b/guix-data-service/web/server.scm @@ -35,6 +35,7 @@ #:use-module (knots) #:use-module (knots web-server) #:use-module (knots thread-pool) + #:use-module (knots parallelism) #:use-module (knots resource-pool) #:use-module (prometheus) #:use-module (guix-data-service utils) @@ -246,15 +247,17 @@ port. Also, the port used can be changed by passing the --port option.\n" exn) (raise-exception exn)) (lambda () - (call-with-resource-from-pool (background-connection-pool) - (lambda (conn) - (let ((build-ids - (select-background-processing-build-ids conn))) - (unless (null? build-ids) - (simple-format #t "processing ~A builds from the background queue\n" - (length build-ids))) - (for-each - (lambda (build-id) + (let ((build-ids + (call-with-resource-from-pool (background-connection-pool) + (lambda (conn) + (select-background-processing-build-ids conn))))) + (unless (null? build-ids) + (simple-format #t "processing ~A builds from the background queue\n" + (length build-ids))) + (fibers-batch-for-each + (lambda (build-id) + (call-with-resource-from-pool (background-connection-pool) + (lambda (conn) (let ((status (select-latest-build-status-by-build-id conn build-id))) @@ -275,8 +278,11 @@ port. Also, the port used can be changed by passing the --port option.\n" (list build-id))))) (delete-background-processing-entries-for-build-ids conn - (list build-id))) - build-ids))))))) + (list build-id))))) + (assq-ref (resource-pool-stats (background-connection-pool) + #:timeout #f) + 'resources) + build-ids))))) #:unwind? #t)) #:parallel? #t)