From a970603ad11fde60c4f42d9fcf493a58e28b3b83 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 5 Nov 2008 04:52:52 +0000 Subject: [PATCH] * Get dependencies from the database. --- src/scheduler.pl | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/scheduler.pl b/src/scheduler.pl index e3547fcb..35a9a42f 100644 --- a/src/scheduler.pl +++ b/src/scheduler.pl @@ -9,6 +9,12 @@ use HydraFrontend::Schema; my $db = HydraFrontend::Schema->connect("dbi:SQLite:dbname=hydra.sqlite", "", "", {}); +sub isValidPath { + my $path = shift; + return system("nix-store --check-validity $path 2> /dev/null") == 0; +} + + sub buildJob { my ($project, $jobset, $jobName, $drvPath, $outPath) = @_; @@ -22,7 +28,7 @@ sub buildJob { my $startTime = 0; my $stopTime = 0; - if (system("nix-store --check-validity $outPath 2> /dev/null") != 0) { + if (!isValidPath($outPath)) { $isCachedBuild = 0; $startTime = time(); @@ -150,12 +156,34 @@ sub checkJobSet { if (defined $jobExpr->{function}->{attrspat}) { foreach my $argName (keys(%{$jobExpr->{function}->{attrspat}->{attr}})) { print " needs input $argName\n"; - die "missing input `$argName'" if !defined $inputInfo->{$argName}; - $extraArgs .= " --arg $argName '{path = " . $inputInfo->{$argName}->{storePath} . ";}'"; + my $storePath; + if (defined $inputInfo->{$argName}) { + # The argument name matches an input. + $storePath = $inputInfo->{$argName}->{storePath}; + } else { + (my $prevBuild) = $db->resultset('Builds')->search( + {project => $project->name, jobset => $jobset->name, attrname => $argName}, + {order_by => "timestamp DESC", rows => 1}); + if (defined $prevBuild) { + # The argument name matches a previously built + # job in this jobset. Pick the most recent + # build. !!! refine the selection criteria: + # e.g., most recent successful build. + if (!isValidPath($prevBuild->outpath)) { + die "input path " . $prevBuild->outpath . " has been garbage-collected"; + } + $storePath = $prevBuild->outpath; + } else { + # !!! reschedule? + die "missing input `$argName'"; + } + } + $extraArgs .= " --arg $argName '{path = " . $storePath . ";}'"; } } # Instantiate the store derivation. + print "$extraArgs\n"; my $drvPath = `nix-instantiate $nixExprPath --attr $jobName $extraArgs` or die "cannot evaluate the Nix expression containing the job definitions: $?"; chomp $drvPath;