diff --git a/src/lib/Hydra/Controller/Build.pm b/src/lib/Hydra/Controller/Build.pm index 52bf9d99..6c7521a3 100644 --- a/src/lib/Hydra/Controller/Build.pm +++ b/src/lib/Hydra/Controller/Build.pm @@ -357,26 +357,12 @@ sub restart : Chained('build') PathPart Args(0) { my $build = $c->stash->{build}; requireProjectOwner($c, $build->project); + + my $drvpath = $build->drvpath ; + error($c, "This build cannot be restarted.") + unless $build->finished && -f $drvpath ; - txn_do($c->model('DB')->schema, sub { - my $drvpath = $build->drvpath ; - error($c, "This build cannot be restarted.") - unless $build->finished && -f $drvpath ; - - my $cmd = "`nix-store -qR $drvpath`"; - my $r = `nix-store --clear-failed-paths $cmd`; - - $build->update({finished => 0, timestamp => time}); - - $build->resultInfo->delete; - - $c->model('DB::BuildSchedulingInfo')->create( - { id => $build->id - , priority => 0 # don't know the original priority anymore... - , busy => 0 - , locker => "" - }); - }); + restartBuild($build); $c->flash->{buildMsg} = "Build has been restarted."; diff --git a/src/lib/Hydra/Helper/AddBuilds.pm b/src/lib/Hydra/Helper/AddBuilds.pm index f1b66a1e..791ae17f 100644 --- a/src/lib/Hydra/Helper/AddBuilds.pm +++ b/src/lib/Hydra/Helper/AddBuilds.pm @@ -12,7 +12,7 @@ use File::stat; use File::Path; our @ISA = qw(Exporter); -our @EXPORT = qw(fetchInput evalJobs checkBuild inputsToArgs captureStdoutStderr getReleaseName getBuildLog addBuildProducts); +our @EXPORT = qw(fetchInput evalJobs checkBuild inputsToArgs captureStdoutStderr getReleaseName getBuildLog addBuildProducts restartBuild); sub scmPath { return getHydraPath . "/scm" ; @@ -764,3 +764,30 @@ sub checkBuild { return $build; }; + + +sub restartBuild { + my ($db, $build) = @_; + + txn_do($db, sub { + my $drvpath = $build->drvpath ; + my $outpath = $build->outpath ; + + my $paths = ""; + foreach my $bs ($build->buildsteps) { + $paths = $paths . " " . $bs->outpath; + } + + my $r = `nix-store --clear-failed-paths $paths $outpath`; + $build->update({finished => 0, timestamp => time}); + + $build->resultInfo->delete; + + $db->resultset('BuildSchedulingInfo')->create( + { id => $build->id + , priority => 0 # don't know the original priority anymore... + , busy => 0 + , locker => "" + }); + }); +}