From ed114265cdde01c71193f38d00e6fef8a6b1bebb Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sat, 12 Nov 2022 11:36:19 +0000 Subject: [PATCH] Handle deleting from blocked_builds when builds are scheduled As scheduling a build might unblock others. --- guix-data-service/model/blocked-builds.scm | 31 +++++++++++++++++-- .../web/build-server/controller.scm | 2 +- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/guix-data-service/model/blocked-builds.scm b/guix-data-service/model/blocked-builds.scm index 708aaba..480b554 100644 --- a/guix-data-service/model/blocked-builds.scm +++ b/guix-data-service/model/blocked-builds.scm @@ -27,7 +27,7 @@ #:use-module (guix-data-service model system) #:use-module (guix-data-service model guix-revision) #:use-module (guix-data-service model build) - #:export (handle-populating-blocked-builds-for-scheduled-builds + #:export (handle-blocked-builds-entries-for-scheduled-builds handle-populating-blocked-builds-for-build-failures handle-removing-blocking-build-entries-for-successful-builds @@ -178,7 +178,7 @@ ON CONFLICT DO NOTHING") #t) -(define (handle-populating-blocked-builds-for-scheduled-builds conn build-ids) +(define (handle-blocked-builds-entries-for-scheduled-builds conn build-ids) (define (get-build-details build-id) (define query " @@ -188,6 +188,29 @@ WHERE id = $1") (exec-query conn query (list (number->string build-id)))) + (define delete-query + (string-append + " +DELETE FROM blocked_builds +WHERE EXISTS ( + SELECT 1 + FROM builds + WHERE builds.id IN (" (string-join + (map number->string build-ids) + ", ") + ") + AND EXISTS ( + SELECT 1 + FROM latest_build_status + WHERE latest_build_status.build_id = builds.id + AND latest_build_status.status = 'scheduled' + ) + AND blocked_builds.build_server_id = builds.build_server_id + AND blocked_builds.blocking_derivation_output_details_set_id + = builds.derivation_output_details_set_id +)")) + + ;; Insert entries for each build if it's blocked (for-each (lambda (build-id) (match (get-build-details build-id) @@ -207,6 +230,10 @@ WHERE id = $1") blocking-derivation-output-details-set-ids))))))) build-ids) + ;; This build being scheduled might unblock other builds, so delete the + ;; associated entries + (exec-query conn delete-query '()) + #t) (define (handle-populating-blocked-builds-for-build-failures conn build-ids) diff --git a/guix-data-service/web/build-server/controller.scm b/guix-data-service/web/build-server/controller.scm index 750fb67..a35a62f 100644 --- a/guix-data-service/web/build-server/controller.scm +++ b/guix-data-service/web/build-server/controller.scm @@ -217,7 +217,7 @@ build-ids) (spawn-fiber-for-build-handler - handle-populating-blocked-builds-for-scheduled-builds + handle-blocked-builds-entries-for-scheduled-builds '("scheduled") items build-ids)