summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2018-02-08 14:01:42 +0100
committerLudovic Courtès <ludo@gnu.org>2018-02-08 14:19:19 +0100
commit57410b6cc27b4474360b0a397604a4eb8d29f28a (patch)
treefb92d8c3cfc25e7430c66f5f4d9786515becb4f5
parent49ec76487a2db27a7cab5382823cde72dfe387df (diff)
downloadcuirass-57410b6cc27b4474360b0a397604a4eb8d29f28a.tar
cuirass-57410b6cc27b4474360b0a397604a4eb8d29f28a.tar.gz
base: Account for derivations built behind our back.
Previously any derivation not directly built by Cuirass would be considered as failed because 'handle-build-event' wouldn't see any build event. Here we just make sure the build status recorded in the database corresponds to reality. * src/cuirass/base.scm (update-build-statuses!): New procedure. (spawn-builds): Call it after 'build-derivations&'.
-rw-r--r--src/cuirass/base.scm39
1 files changed, 31 insertions, 8 deletions
diff --git a/src/cuirass/base.scm b/src/cuirass/base.scm
index 9a2024b..ec0a016 100644
--- a/src/cuirass/base.scm
+++ b/src/cuirass/base.scm
@@ -329,6 +329,19 @@ Essentially this procedure inverts the inversion-of-control that
(sort jobs job<?))
+(define (update-build-statuses! store db lst)
+ "Update the build status of the derivations listed in LST, which have just
+been passed to 'build-derivations' (meaning that we can assume that, if their
+outputs are invalid, that they failed to build.)"
+ (define (update! drv)
+ (match (derivation-path->output-paths drv)
+ (((_ . outputs) ...)
+ (if (any (cut valid-path? store <>) outputs)
+ (db-update-build-status! db drv (build-status succeeded))
+ (db-update-build-status! db drv (build-status failed))))))
+
+ (for-each update! lst))
+
(define* (spawn-builds store db jobs
#:key (max-batch-size 200))
"Build the derivations associated with JOBS, a list of job alists, updating
@@ -362,10 +375,14 @@ MAX-BATCH-SIZE items."
(count total))
(if (zero? count)
(log-message "done with ~a derivations" total)
- (let-values (((batch rest)
- (if (> total max-batch-size)
- (split-at jobs max-batch-size)
- (values jobs '()))))
+ (let*-values (((batch rest)
+ (if (> total max-batch-size)
+ (split-at jobs max-batch-size)
+ (values jobs '())))
+ ((drv)
+ (map (lambda (job)
+ (assq-ref job #:derivation))
+ batch)))
(guard (c ((nix-protocol-error? c)
(log-message "batch of builds (partially) failed:\
~a (status: ~a)"
@@ -374,16 +391,22 @@ MAX-BATCH-SIZE items."
(log-message "building batch of ~a jobs (~a/~a)"
max-batch-size (- total count) total)
(let-values (((port finish)
- (build-derivations& store
- (map (lambda (job)
- (assq-ref job #:derivation))
- batch))))
+ (build-derivations& store drv)))
(process-build-log port
(lambda (event state)
(handle-build-event db event))
#t)
(close-port port)
(finish)))
+
+ ;; Most of the time 'handle-build-event' will update the build
+ ;; status of derivations. However, it could be that some
+ ;; derivations were built "behind our back", in which case
+ ;; 'build-derivations' doesn't actually do anything and
+ ;; 'handle-build-event' doesn't see any event. Because of that,
+ ;; adjust DB here.
+ (update-build-statuses! store db drv)
+
(loop rest (max (- total max-batch-size) 0))))))
(define* (handle-build-event db event)