From c58ee6726b5f4d8a209d1af85e393edd0ca4d02a Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Tue, 5 Nov 2024 21:11:02 +0000 Subject: Fix starting with an empty database --- guix-data-service/substitutes.scm | 9 ++++++++- guix-data-service/web/server.scm | 3 +++ scripts/guix-data-service.in | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/guix-data-service/substitutes.scm b/guix-data-service/substitutes.scm index c7a45dc..3603521 100644 --- a/guix-data-service/substitutes.scm +++ b/guix-data-service/substitutes.scm @@ -19,6 +19,7 @@ #:use-module (srfi srfi-1) #:use-module (srfi srfi-19) #:use-module (ice-9 match) + #:use-module (ice-9 atomic) #:use-module (ice-9 threads) #:use-module (fibers) #:use-module (fibers channels) @@ -149,7 +150,7 @@ (lambda (channel) (put-message channel (cons build-server-id build-ids))))))) -(define (start-substitute-query-threads) +(define (start-substitute-query-threads startup-completed?) (define channel (make-channel)) @@ -162,6 +163,9 @@ (set-thread-name "request substitute query")) (const #t)) + (while (not (atomic-box-ref startup-completed?)) + (sleep 1)) + (while #t (with-exception-handler (lambda (exn) @@ -208,6 +212,9 @@ (set-thread-name "bulk substitute query")) (const #t)) + (while (not (atomic-box-ref startup-completed?)) + (sleep 1)) + (while #t (with-exception-handler (lambda (exn) diff --git a/guix-data-service/web/server.scm b/guix-data-service/web/server.scm index 77db774..4e08161 100644 --- a/guix-data-service/web/server.scm +++ b/guix-data-service/web/server.scm @@ -260,6 +260,9 @@ port. Also, the port used can be changed by passing the --port option.\n" (spawn-fiber (lambda () + (while (not (check-startup-completed startup-completed)) + (sleep 1)) + (with-resource-from-pool (background-connection-pool) conn (backfill-guix-revision-package-derivation-distribution-counts conn))) diff --git a/scripts/guix-data-service.in b/scripts/guix-data-service.in index 8a124ee..172838f 100644 --- a/scripts/guix-data-service.in +++ b/scripts/guix-data-service.in @@ -197,7 +197,7 @@ (lambda (port) (simple-format port "~A\n" (getpid))))) - (start-substitute-query-threads) + (start-substitute-query-threads startup-completed) (call-with-new-thread (lambda () -- cgit v1.2.3