From 63306aaf5a6e96481e40fd2975875e0bb9ad664a Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 9 Apr 2015 17:35:04 +0200 Subject: [PATCH] hydra-evaluator: Add some debug code --- src/lib/Hydra/Helper/AddBuilds.pm | 16 +++++++++++++--- src/script/hydra-evaluator | 22 ++++++++++++++++++---- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/lib/Hydra/Helper/AddBuilds.pm b/src/lib/Hydra/Helper/AddBuilds.pm index e43785d2..e01cfd04 100644 --- a/src/lib/Hydra/Helper/AddBuilds.pm +++ b/src/lib/Hydra/Helper/AddBuilds.pm @@ -330,10 +330,20 @@ sub evalJobs { my $nixExprFullPath = $nixExprInput->{storePath} . "/" . $nixExprPath; my $evaluator = ($exprType eq "guile") ? "hydra-eval-guile-jobs" : "hydra-eval-jobs"; - print STDERR "evaluator ${evaluator}\n"; - (my $res, my $jobsJSON, my $stderr) = captureStdoutStderr(10800, - $evaluator, $nixExprFullPath, "--gc-roots-dir", getGCRootsDir, "-j", 1, inputsToArgs($inputInfo, $exprType)); + my @cmd = ($evaluator, $nixExprFullPath, "--gc-roots-dir", getGCRootsDir, "-j", 1, inputsToArgs($inputInfo, $exprType)); + + if (defined $ENV{'HYDRA_DEBUG'}) { + sub escape { + my $s = $_; + $s =~ s/'/'\\''/g; + return "'" . $s . "'"; + } + my @escaped = map escape, @cmd; + print STDERR "evaluator: @escaped\n"; + } + + (my $res, my $jobsJSON, my $stderr) = captureStdoutStderr(10800, @cmd); die "$evaluator returned " . ($res & 127 ? "signal $res" : "exit code " . ($res >> 8)) . ":\n" . ($stderr ? $stderr : "(no output)\n") if $res; diff --git a/src/script/hydra-evaluator b/src/script/hydra-evaluator index 51843770..52d7e9af 100755 --- a/src/script/hydra-evaluator +++ b/src/script/hydra-evaluator @@ -25,6 +25,7 @@ my $plugins = [Hydra::Plugin->instantiate(db => $db, config => $config)]; # Don't check a jobset more than once every five minutes. my $minCheckInterval = 5 * 60; +my $dryRun = defined $ENV{'HYDRA_DRY_RUN'}; sub fetchInputs { @@ -112,7 +113,7 @@ sub checkJobsetWrapped { my $msg = $@; print STDERR $msg; txn_do($db, sub { - $jobset->update({ lastcheckedtime => time, fetcherrormsg => $msg }); + $jobset->update({ lastcheckedtime => time, fetcherrormsg => $msg }) if !$dryRun; }); return; } @@ -124,7 +125,7 @@ sub checkJobsetWrapped { my @args = ($jobset->nixexprinput, $jobset->nixexprpath, inputsToArgs($inputInfo, $exprType)); my $argsHash = sha256_hex("@args"); my $prevEval = getPrevJobsetEval($db, $jobset, 0); - if (defined $prevEval && $prevEval->hash eq $argsHash) { + if (defined $prevEval && $prevEval->hash eq $argsHash && !$dryRun) { print STDERR " jobset is unchanged, skipping\n"; txn_do($db, sub { $jobset->update({ lastcheckedtime => time, fetcherrormsg => undef }); @@ -137,6 +138,18 @@ sub checkJobsetWrapped { my ($jobs, $nixExprInput) = evalJobs($inputInfo, $exprType, $jobset->nixexprinput, $jobset->nixexprpath); my $evalStop = time; + if ($dryRun) { + foreach my $name (keys %{$jobs}) { + my $job = $jobs->{$name}; + if (defined $job->{drvPath}) { + print STDERR "good job $name: $job->{drvPath}\n"; + } else { + print STDERR "failed job $name: $job->{error}\n"; + } + } + return; + } + $jobs->{$_}->{jobName} = $_ for keys %{$jobs}; my $jobOutPathMap = {}; @@ -268,7 +281,7 @@ sub checkJobset { txn_do($db, sub { $jobset->update({lastcheckedtime => time}); setJobsetError($jobset, $msg); - }); + }) if !$dryRun; $failed = 1; } @@ -280,8 +293,9 @@ sub checkJobset { my $new = $jobset->get_from_storage(); $jobset->update({ triggertime => undef }) if $new->triggertime == $triggerTime; - }); + }) if !$dryRun; } + return $failed; }