From 166d56088f136729bc4ef6de6096eba16367a9da Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Mon, 8 Jul 2013 13:35:34 -0400 Subject: [PATCH] Call buildFinished when a cached build is added Signed-off-by: Shea Levy --- src/lib/Hydra/Controller/Build.pm | 2 +- src/lib/Hydra/Helper/AddBuilds.pm | 4 +++- src/lib/Hydra/Helper/PluginHooks.pm | 22 ++++++++++++++++++++++ src/script/hydra-build | 18 +++--------------- src/script/hydra-evaluator | 2 +- 5 files changed, 30 insertions(+), 18 deletions(-) create mode 100644 src/lib/Hydra/Helper/PluginHooks.pm diff --git a/src/lib/Hydra/Controller/Build.pm b/src/lib/Hydra/Controller/Build.pm index 18ca624d..1018bd60 100644 --- a/src/lib/Hydra/Controller/Build.pm +++ b/src/lib/Hydra/Controller/Build.pm @@ -575,7 +575,7 @@ sub clone_submit : Chained('buildChain') PathPart('clone/submit') Args(0) { my %currentBuilds; my $newBuild = checkBuild( $c->model('DB'), $build->project, $build->jobset, - $inputInfo, $nixExprInput, $job, \%currentBuilds, undef, {}); + $inputInfo, $nixExprInput, $job, \%currentBuilds, undef, {}, $c->hydra_plugins); error($c, "This build has already been performed.") unless $newBuild; diff --git a/src/lib/Hydra/Helper/AddBuilds.pm b/src/lib/Hydra/Helper/AddBuilds.pm index b2106ffa..6bad9e81 100644 --- a/src/lib/Hydra/Helper/AddBuilds.pm +++ b/src/lib/Hydra/Helper/AddBuilds.pm @@ -15,6 +15,7 @@ use File::Path; use File::Temp; use File::Spec; use File::Slurp; +use Hydra::Helper::PluginHooks; our @ISA = qw(Exporter); our @EXPORT = qw( @@ -389,7 +390,7 @@ sub getPrevJobsetEval { # Check whether to add the build described by $buildInfo. sub checkBuild { - my ($db, $project, $jobset, $inputInfo, $nixExprInput, $buildInfo, $buildIds, $prevEval, $jobOutPathMap) = @_; + my ($db, $project, $jobset, $inputInfo, $nixExprInput, $buildInfo, $buildIds, $prevEval, $jobOutPathMap, $plugins) = @_; my @outputNames = sort keys %{$buildInfo->{output}}; die unless scalar @outputNames; @@ -517,6 +518,7 @@ sub checkBuild { if ($build->iscachedbuild) { print STDERR " marked as cached build ", $build->id, "\n"; addBuildProducts($db, $build); + notifyBuildFinished($plugins, $build, []); } else { print STDERR " added to queue as build ", $build->id, "\n"; } diff --git a/src/lib/Hydra/Helper/PluginHooks.pm b/src/lib/Hydra/Helper/PluginHooks.pm new file mode 100644 index 00000000..4000045b --- /dev/null +++ b/src/lib/Hydra/Helper/PluginHooks.pm @@ -0,0 +1,22 @@ +package Hydra::Helper::PluginHooks; + +use strict; +use Exporter; + +our @ISA = qw(Exporter); +our @EXPORT = qw( + notifyBuildFinished); + +sub notifyBuildFinished { + my ($plugins, $build, $dependents) = @_; + foreach my $plugin (@{$plugins}) { + eval { + $plugin->buildFinished($build, $dependents); + }; + if ($@) { + print STDERR "$plugin->buildFinished: $@\n"; + } + } +} + +1; diff --git a/src/script/hydra-build b/src/script/hydra-build index ab2650db..54232458 100755 --- a/src/script/hydra-build +++ b/src/script/hydra-build @@ -8,6 +8,7 @@ use Nix::Store; use Hydra::Plugin; use Hydra::Schema; use Hydra::Helper::Nix; +use Hydra::Helper::PluginHooks; use Hydra::Model::DB; use Hydra::Helper::AddBuilds; @@ -80,19 +81,6 @@ sub failDependents { } -sub notify { - my ($build, $dependents) = @_; - foreach my $plugin (@plugins) { - eval { - $plugin->buildFinished($build, $dependents); - }; - if ($@) { - print STDERR "$plugin->buildFinished: $@\n"; - } - } -} - - sub doBuild { my ($build) = @_; @@ -319,7 +307,7 @@ sub doBuild { }); - notify($build, $dependents); + notifyBuildFinished(\@plugins, $build, $dependents); } @@ -328,7 +316,7 @@ print STDERR "performing build $buildId\n"; if ($ENV{'HYDRA_MAIL_TEST'}) { my $build = $db->resultset('Builds')->find($buildId); - notify($build, []); + notifyBuildFinished(\@plugins, $build, []); exit 0; } diff --git a/src/script/hydra-evaluator b/src/script/hydra-evaluator index 50e0e448..5bfed9e3 100755 --- a/src/script/hydra-evaluator +++ b/src/script/hydra-evaluator @@ -148,7 +148,7 @@ sub checkJobsetWrapped { foreach my $job (permute @{$jobs->{job}}) { next if $job->{jobName} eq ""; print STDERR " considering job " . $project->name, ":", $jobset->name, ":", $job->{jobName} . "\n"; - checkBuild($db, $project, $jobset, $inputInfo, $nixExprInput, $job, \%buildIds, $prevEval, $jobOutPathMap); + checkBuild($db, $project, $jobset, $inputInfo, $nixExprInput, $job, \%buildIds, $prevEval, $jobOutPathMap, $plugins); } # Update the last checked times and error messages for each