forked from lix-project/hydra
* Allow users to change the value of a build's "keep" flag, which
prevents the build output from being garbage collected.
This commit is contained in:
parent
eeddf5752d
commit
32f0665d2c
|
@ -214,9 +214,7 @@ sub cancel : Chained('build') PathPart Args(0) {
|
||||||
# builds as well, but we would have to send a signal or
|
# builds as well, but we would have to send a signal or
|
||||||
# something to the build process.
|
# something to the build process.
|
||||||
|
|
||||||
$build->finished(1);
|
$build->update({finished => 1, timestamp => time});
|
||||||
$build->timestamp(time());
|
|
||||||
$build->update;
|
|
||||||
|
|
||||||
$c->model('DB::BuildResultInfo')->create(
|
$c->model('DB::BuildResultInfo')->create(
|
||||||
{ id => $build->id
|
{ id => $build->id
|
||||||
|
@ -233,4 +231,24 @@ sub cancel : Chained('build') PathPart Args(0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub keep : Chained('build') PathPart Args(1) {
|
||||||
|
my ($self, $c, $newStatus) = @_;
|
||||||
|
|
||||||
|
my $build = $c->stash->{build};
|
||||||
|
|
||||||
|
requireProjectOwner($c, $build->project);
|
||||||
|
|
||||||
|
die unless $newStatus == 0 || $newStatus == 1;
|
||||||
|
|
||||||
|
$c->model('DB')->schema->txn_do(sub {
|
||||||
|
$build->resultInfo->update({keep => int $newStatus});
|
||||||
|
});
|
||||||
|
|
||||||
|
$c->flash->{buildMsg} =
|
||||||
|
$newStatus == 0 ? "Build will not be kept." : "Build will be kept.";
|
||||||
|
|
||||||
|
$c->res->redirect($c->uri_for($self->action_for("view_build"), $c->req->captures));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -57,7 +57,7 @@
|
||||||
<span class="error">Build failed</span>
|
<span class="error">Build failed</span>
|
||||||
(see <a href="#nix-error">below</a>)
|
(see <a href="#nix-error">below</a>)
|
||||||
[% END %]
|
[% END %]
|
||||||
[% IF build.resultInfo.buildstatus == 3 || build.resultInfo.buildstatus == 4 %]
|
[% IF c.user_exists && (build.resultInfo.buildstatus == 3 || build.resultInfo.buildstatus == 4) %]
|
||||||
<form action="[% c.uri_for('/build' build.id 'restart') %]" method="post" class="inline">
|
<form action="[% c.uri_for('/build' build.id 'restart') %]" method="post" class="inline">
|
||||||
<button id="restart" type="submit">Restart</button>
|
<button id="restart" type="submit">Restart</button>
|
||||||
</form>
|
</form>
|
||||||
|
@ -174,6 +174,30 @@
|
||||||
<td>[% build.schedulingInfo.priority %]</td>
|
<td>[% build.schedulingInfo.priority %]</td>
|
||||||
</tr>
|
</tr>
|
||||||
[% END %]
|
[% END %]
|
||||||
|
[% IF build.finished && build.buildproducts %]
|
||||||
|
<tr>
|
||||||
|
<th>Availability:</th>
|
||||||
|
<td>
|
||||||
|
[% IF !available %]
|
||||||
|
<em>Build output is no longer available</em>
|
||||||
|
[% ELSIF build.resultInfo.keep %]
|
||||||
|
<em>Build output will be kept permanently</em>
|
||||||
|
[% IF c.user_exists %]
|
||||||
|
<form action="[% c.uri_for('/build' build.id 'keep' 0) %]" method="post" class="inline">
|
||||||
|
<button id="unkeep" type="submit">Unkeep</button>
|
||||||
|
</form>
|
||||||
|
[% END %]
|
||||||
|
[% ELSE %]
|
||||||
|
<em>Build output is available, but may be garbage-collected</em>
|
||||||
|
[% IF c.user_exists %]
|
||||||
|
<form action="[% c.uri_for('/build' build.id 'keep' 1) %]" method="post" class="inline">
|
||||||
|
<button id="keep" type="submit">Keep</button>
|
||||||
|
</form>
|
||||||
|
[% END %]
|
||||||
|
[% END %]
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
[% END %]
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ sub registerRoot {
|
||||||
|
|
||||||
sub keepBuild {
|
sub keepBuild {
|
||||||
my ($build) = @_;
|
my ($build) = @_;
|
||||||
print "keeping build ", $build->id, " (",
|
print STDERR "keeping build ", $build->id, " (",
|
||||||
strftime("%Y-%m-%d %H:%M:%S", localtime($build->timestamp)), ")\n";
|
strftime("%Y-%m-%d %H:%M:%S", localtime($build->timestamp)), ")\n";
|
||||||
if (isValidPath($build->outpath)) {
|
if (isValidPath($build->outpath)) {
|
||||||
registerRoot $build->outpath;
|
registerRoot $build->outpath;
|
||||||
|
@ -37,16 +37,16 @@ foreach my $project ($db->resultset('Projects')->all) {
|
||||||
|
|
||||||
# Go over all jobs in this project.
|
# Go over all jobs in this project.
|
||||||
|
|
||||||
foreach my $job ($project->builds->search({},
|
foreach my $job ($project->jobs->all) {
|
||||||
{select => [{distinct => 'job'}], as => ['job']}))
|
print STDERR "*** looking for builds to keep in job ",
|
||||||
{
|
$project->name, ":", $job->jobset->name, ":", $job->name, "\n";
|
||||||
print "*** looking for builds to keep in job ", $project->name, ":", $job->job, "\n";
|
|
||||||
|
|
||||||
# Keep the N most recent successful builds for each job and
|
# Keep the N most recent successful builds for each job and
|
||||||
# platform.
|
# platform.
|
||||||
my @recentBuilds = $project->builds->search(
|
# !!! Take time into account? E.g. don't delete builds that
|
||||||
{ job => $job->job
|
# are younger than N days.
|
||||||
, finished => 1
|
my @recentBuilds = $job->builds->search(
|
||||||
|
{ finished => 1
|
||||||
, buildStatus => 0 # == success
|
, buildStatus => 0 # == success
|
||||||
},
|
},
|
||||||
{ join => 'resultInfo'
|
{ join => 'resultInfo'
|
||||||
|
@ -55,13 +55,12 @@ foreach my $project ($db->resultset('Projects')->all) {
|
||||||
});
|
});
|
||||||
|
|
||||||
keepBuild $_ foreach @recentBuilds;
|
keepBuild $_ foreach @recentBuilds;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Go over all releases in this project.
|
# Go over all releases in this project.
|
||||||
|
|
||||||
foreach my $releaseSet ($project->releasesets->all) {
|
foreach my $releaseSet ($project->releasesets->all) {
|
||||||
print "*** looking for builds to keep in release set ", $project->name, ":", $releaseSet->name, "\n";
|
print STDERR "*** looking for builds to keep in release set ", $project->name, ":", $releaseSet->name, "\n";
|
||||||
|
|
||||||
(my $primaryJob) = $releaseSet->releasesetjobs->search({isprimary => 1});
|
(my $primaryJob) = $releaseSet->releasesetjobs->search({isprimary => 1});
|
||||||
my $jobs = [$releaseSet->releasesetjobs->all];
|
my $jobs = [$releaseSet->releasesetjobs->all];
|
||||||
|
@ -69,7 +68,7 @@ foreach my $project ($db->resultset('Projects')->all) {
|
||||||
# Keep all builds belonging to the most recent successful release.
|
# Keep all builds belonging to the most recent successful release.
|
||||||
my $latest = getLatestSuccessfulRelease($project, $primaryJob, $jobs);
|
my $latest = getLatestSuccessfulRelease($project, $primaryJob, $jobs);
|
||||||
if (defined $latest) {
|
if (defined $latest) {
|
||||||
print "keeping latest successful release ", $latest->id, " (", $latest->get_column('releasename'), ")\n";
|
print STDERR "keeping latest successful release ", $latest->id, " (", $latest->get_column('releasename'), ")\n";
|
||||||
my $release = getRelease($latest, $jobs);
|
my $release = getRelease($latest, $jobs);
|
||||||
keepBuild $_->{build} foreach @{$release->{jobs}};
|
keepBuild $_->{build} foreach @{$release->{jobs}};
|
||||||
}
|
}
|
||||||
|
@ -79,16 +78,16 @@ foreach my $project ($db->resultset('Projects')->all) {
|
||||||
|
|
||||||
|
|
||||||
# Keep all builds that have been marked as "keep".
|
# Keep all builds that have been marked as "keep".
|
||||||
print "*** looking for kept builds\n";
|
print STDERR "*** looking for kept builds\n";
|
||||||
my @buildsToKeep = $db->resultset('Builds')->search({finished => 1, keep => 1}, {join => 'resultInfo'});
|
my @buildsToKeep = $db->resultset('Builds')->search({finished => 1, keep => 1}, {join => 'resultInfo'});
|
||||||
keepBuild $_ foreach @buildsToKeep;
|
keepBuild $_ foreach @buildsToKeep;
|
||||||
|
|
||||||
|
|
||||||
# For scheduled builds, we register the derivation and the output as a GC root.
|
# For scheduled builds, we register the derivation and the output as a GC root.
|
||||||
print "*** looking for scheduled builds\n";
|
print STDERR "*** looking for scheduled builds\n";
|
||||||
foreach my $build ($db->resultset('Builds')->search({finished => 0}, {join => 'schedulingInfo'})) {
|
foreach my $build ($db->resultset('Builds')->search({finished => 0}, {join => 'schedulingInfo'})) {
|
||||||
if (isValidPath($build->drvpath)) {
|
if (isValidPath($build->drvpath)) {
|
||||||
print "keeping scheduled build ", $build->id, " (",
|
print STDERR "keeping scheduled build ", $build->id, " (",
|
||||||
strftime("%Y-%m-%d %H:%M:%S", localtime($build->timestamp)), ")\n";
|
strftime("%Y-%m-%d %H:%M:%S", localtime($build->timestamp)), ")\n";
|
||||||
registerRoot $build->drvpath;
|
registerRoot $build->drvpath;
|
||||||
registerRoot $build->outpath;
|
registerRoot $build->outpath;
|
||||||
|
@ -99,7 +98,7 @@ foreach my $build ($db->resultset('Builds')->search({finished => 0}, {join => 's
|
||||||
|
|
||||||
|
|
||||||
# Remove existing roots that are no longer wanted. !!! racy
|
# Remove existing roots that are no longer wanted. !!! racy
|
||||||
print "*** removing unneeded GC roots\n";
|
print STDERR "*** removing unneeded GC roots\n";
|
||||||
|
|
||||||
my $gcRootsDir = getGCRootsDir;
|
my $gcRootsDir = getGCRootsDir;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue