hydra-evaluator: Don't require $HYDRA_CONFIG

This commit is contained in:
Eelco Dolstra 2013-01-22 13:19:28 +01:00
parent fc39034772
commit f188fe5683
3 changed files with 41 additions and 40 deletions

View file

@ -9,7 +9,7 @@ use Hydra::Model::DB;
our @ISA = qw(Exporter);
our @EXPORT = qw(
getHydraHome getHydraConf txn_do
getHydraHome getHydraConfig txn_do
registerRoot getGCRootsDir gcRootFor
getPrimaryBuildsForView
getPrimaryBuildTotal
@ -23,10 +23,11 @@ sub getHydraHome {
}
sub getHydraConf {
sub getHydraConfig {
my $conf = $ENV{"HYDRA_CONFIG"} || (Hydra::Model::DB::getHydraPath . "/hydra.conf");
die "The HYDRA_CONFIG file ($conf) does not exist!\n" unless -f $conf;
return $conf;
return {} unless -f $conf;
my %config = new Config::General($conf)->getall;
return \%config;
}

View file

@ -24,21 +24,21 @@ STDOUT->autoflush();
my $db = Hydra::Model::DB->new();
my $config = getHydraConfig();
my %config = new Config::General(getHydraConf)->getall;
sub sendTwitterNotification {
my ($build) = @_;
return unless (defined $ENV{'TWITTER_USER'} && defined $ENV{'TWITTER_PASS'});
my $addURL = defined $config{'base_uri'};
my $addURL = defined $config->{'base_uri'};
my $jobName = $build->project->name . ":" . $build->jobset->name . ":" . $build->job->name;
my $status = $build->buildstatus == 0 ? "SUCCEEDED" : "FAILED";
my $system = $build->system;
my $duration = ($build->stoptime - $build->starttime) . " seconds";
my $url = $config{'base_uri'}."/build/".$build->id ;
my $url = $config->{'base_uri'}."/build/".$build->id ;
my $nt = Net::Twitter::Lite->new(
username => $ENV{'TWITTER_USER'},
@ -83,14 +83,14 @@ sub sendEmailNotification {
my $prevBuild;
($prevBuild) = $db->resultset('Builds')->search(
{ project => $build->project->name
{ project => $build->project->name
, jobset => $build->jobset->name
, job => $build->job->name
, system => $build->system
, finished => 1
, id => { '<', $build->id }
, -not => { buildstatus => { -in => [4, 3]} }
}, { order_by => ["id DESC"] }
}, { order_by => ["id DESC"] }
);
# if build is cancelled or aborted, do not send email
@ -112,10 +112,10 @@ sub sendEmailNotification {
my $status = statusDescription($build->buildstatus);
my $baseurl = hostname_long ;
my $sender = $config{'notification_sender'} ||
my $sender = $config->{'notification_sender'} ||
(($ENV{'USER'} || "hydra") . "@" . $baseurl);
my $selfURI = $config{'base_uri'} || "http://localhost:3000";
my $selfURI = $config->{'base_uri'} || "http://localhost:3000";
sub showTime { my ($x) = @_; return strftime('%Y-%m-%d %H:%M:%S', localtime($x)); }
@ -235,9 +235,9 @@ sub doBuild {
# Run Nix to perform the build, and monitor the stderr output
# to get notifications about specific build steps, the
# associated log files, etc.
# Note: `--timeout' was added in Nix 1.0pre27564, June 2011.
# Note: `--timeout' was added in Nix 1.0pre27564, June 2011.
my $cmd = "nix-store --realise $drvPath " .
"--timeout $timeout " .
"--timeout $timeout " .
"--max-silent-time $maxsilent --keep-going --fallback " .
"--no-build-output --log-type flat --print-build-trace " .
"--add-root " . gcRootFor $outPath . " 2>&1";
@ -259,7 +259,7 @@ sub doBuild {
}
if (/^@\s+build-started\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)$/) {
my $drvPathStep = $1;
my $drvPathStep = $1;
txn_do($db, sub {
$build->buildsteps->create(
{ stepnr => ($buildSteps{$drvPathStep} = $buildStepNr++)
@ -276,12 +276,12 @@ sub doBuild {
elsif (/^@\s+build-remote\s+(\S+)\s+(\S+)$/) {
my $drvPathStep = $1;
my $machine = $2;
my $machine = $2;
txn_do($db, sub {
my $step = $build->buildsteps->find({stepnr => $buildSteps{$drvPathStep}}) or die;
$step->update({machine => $machine});
});
}
}
elsif (/^@\s+build-succeeded\s+(\S+)\s+(\S+)$/) {
my $drvPathStep = $1;
@ -389,8 +389,8 @@ sub doBuild {
my @closure = computeFSClosure(0, 0, $outPath);
foreach my $path (@closure) {
my ($deriver, $hash, $time, $narSize, $refs) = queryPathInfo($path, 0);
$closuresize += $narSize;
my ($deriver, $hash, $time, $narSize, $refs) = queryPathInfo($path, 0);
$closuresize += $narSize;
}
}
@ -446,8 +446,8 @@ if ($ENV{'HYDRA_TWITTER_TEST'}) {
my $build;
txn_do($db, sub {
$build = $db->resultset('Builds')->find($buildId);
die "build $buildId doesn't exist" unless defined $build;
die "build $buildId already done" if $build->finished;
die "build $buildId doesn't exist\n" unless defined $build;
die "build $buildId already done\n" if $build->finished;
if ($build->busy != 0 && $build->locker != getppid) {
die "build $buildId is already being built";
}

View file

@ -18,17 +18,17 @@ use Data::Dump qw(dump);
STDOUT->autoflush();
my $db = Hydra::Model::DB->new();
my %config = new Config::General(getHydraConf)->getall;
my $config = getHydraConfig();
sub fetchInputs {
my ($project, $jobset, $inputInfo) = @_;
foreach my $input ($jobset->jobsetinputs->all) {
foreach my $alt ($input->jobsetinputalts->all) {
my @info = fetchInput($db, $project, $jobset, $input->name, $input->type, $alt->value);
foreach my $info_el (@info) {
push @{$$inputInfo{$input->name}}, $info_el if defined $info_el;
}
my @info = fetchInput($db, $project, $jobset, $input->name, $input->type, $alt->value);
foreach my $info_el (@info) {
push @{$$inputInfo{$input->name}}, $info_el if defined $info_el;
}
}
}
}
@ -41,7 +41,7 @@ sub setJobsetError {
$jobset->update({errormsg => $errorMsg, errortime => time});
});
};
sendJobsetErrorNotification($jobset, $errorMsg);
sendJobsetErrorNotification($jobset, $errorMsg);
}
@ -49,13 +49,13 @@ sub sendJobsetErrorNotification() {
my ($jobset, $errorMsg) = @_;
return if $jobset->project->owner->emailonerror == 0;
return if $errorMsg eq "";
return if $errorMsg eq "";
my $url = hostname_long;
my $projectName = $jobset->project->name;
my $jobsetName = $jobset->name;
my $sender = $config{'notification_sender'} ||
my $sender = $config->{'notification_sender'} ||
(($ENV{'USER'} || "hydra") . "@" . $url);
my $body = "Hi,\n"
@ -76,7 +76,7 @@ sub sendJobsetErrorNotification() {
'X-Hydra-Instance' => $url,
'X-Hydra-Project' => $projectName,
'X-Hydra-Jobset' => $jobsetName
],
],
body => ""
);
$email->body_set($body);
@ -90,7 +90,7 @@ sub sendJobsetErrorNotification() {
sub permute {
my @list = @_;
for (my $n = scalar @list - 1; $n > 0; $n--) {
my $k = int(rand($n + 1)); # 0 <= $k <= $n
my $k = int(rand($n + 1)); # 0 <= $k <= $n
@list[$n, $k] = @list[$k, $n];
}
return @list;
@ -101,7 +101,7 @@ sub checkJobset {
my ($project, $jobset) = @_;
my $inputInfo = {};
my $exprType = $jobset->nixexprpath =~ /.scm$/ ? "guile" : "nix";
# Fetch all values for all inputs.
my $checkoutStart = time;
fetchInputs($project, $jobset, $inputInfo);
@ -120,7 +120,7 @@ sub checkJobset {
});
return;
}
# Evaluate the job expression.
my $evalStart = time;
my ($jobs, $nixExprInput) = evalJobs($inputInfo, $exprType, $jobset->nixexprinput, $jobset->nixexprpath);
@ -129,7 +129,7 @@ sub checkJobset {
my $jobOutPathMap = {};
txn_do($db, sub {
my $prevEval = getPrevJobsetEval($db, $jobset, 1);
# Clear the "current" flag on all builds. Since we're in a
@ -151,7 +151,7 @@ sub checkJobset {
push @{$failedJobNames{$_->{location}}}, $_->{msg} foreach @{$jobs->{error}};
$jobset->update({lastcheckedtime => time});
$_->update({ errormsg => $failedJobNames{$_->name} ? join '\n', @{$failedJobNames{$_->name}} : undef })
foreach $jobset->jobs->all;
@ -173,7 +173,7 @@ sub checkJobset {
while (my ($id, $new) = each %buildIds) {
$ev->jobsetevalmembers->create({ build => $id, isnew => $new });
}
foreach my $name (keys %{$inputInfo}) {
for (my $n = 0; $n < scalar(@{$inputInfo->{$name}}); $n++) {
my $input = $inputInfo->{$name}->[$n];
@ -190,7 +190,7 @@ sub checkJobset {
});
}
}
print STDERR " created new eval ", $ev->id, "\n";
$ev->builds->update({iscurrent => 1});
} else {
@ -198,7 +198,7 @@ sub checkJobset {
$prevEval->builds->update({iscurrent => 1}) if defined $prevEval;
}
});
# Store the error messages for jobs that failed to evaluate.
my $msg = "";
foreach my $error (@{$jobs->{error}}) {
@ -221,13 +221,13 @@ sub checkJobset {
sub checkJobsetWrapped {
my ($project, $jobset) = @_;
print STDERR "considering jobset ", $project->name, ":", $jobset->name, "\n";
eval {
checkJobset($project, $jobset);
};
if ($@) {
my $msg = $@;
print STDERR "error evaluating jobset ", $jobset->name, ": $msg";