forked from lix-project/hydra
Merge pull request #1119 from DeterminateSystems/project-jobset/update-gc-roots
Project jobset: update-gc-roots
This commit is contained in:
commit
9671d4d135
|
@ -25,7 +25,7 @@ sub addRoot {
|
||||||
|
|
||||||
|
|
||||||
my @columns =
|
my @columns =
|
||||||
( "id", "project", "jobset", "job", "system", "finished", "drvpath", "timestamp", "buildstatus"
|
( "id", "jobset_id", "job", "system", "finished", "drvpath", "timestamp", "buildstatus"
|
||||||
, { "outpaths" => \ "(select string_agg(path, ' ') from BuildOutputs where build = me.id)" }
|
, { "outpaths" => \ "(select string_agg(path, ' ') from BuildOutputs where build = me.id)" }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -35,8 +35,16 @@ sub keepBuild {
|
||||||
my ($build, $keepFailedDrvs) = @_;
|
my ($build, $keepFailedDrvs) = @_;
|
||||||
return if defined $seenBuilds{$build->id};
|
return if defined $seenBuilds{$build->id};
|
||||||
$seenBuilds{$build->id} = 1;
|
$seenBuilds{$build->id} = 1;
|
||||||
|
|
||||||
|
$build->finished;
|
||||||
|
|
||||||
|
# After #1093 merges this can become $build->jobset;
|
||||||
|
# However, with ->jobset being a column on master
|
||||||
|
# it seems DBIX gets a bit confused.
|
||||||
|
my ($jobset) = $build->search_related('jobset')->first;
|
||||||
|
|
||||||
print STDERR " keeping ", ($build->finished ? "" : "scheduled "), "build ", $build->id, " (",
|
print STDERR " keeping ", ($build->finished ? "" : "scheduled "), "build ", $build->id, " (",
|
||||||
$build->get_column('project'), ":", $build->get_column('jobset'), ":", $build->get_column('job'), "; ",
|
$jobset->get_column('project'), ":", $jobset->get_column('name'), ":", $build->get_column('job'), "; ",
|
||||||
$build->system, "; ",
|
$build->system, "; ",
|
||||||
strftime("%Y-%m-%d %H:%M:%S", localtime($build->timestamp)), ")\n";
|
strftime("%Y-%m-%d %H:%M:%S", localtime($build->timestamp)), ")\n";
|
||||||
if (isLocalStore &&
|
if (isLocalStore &&
|
||||||
|
@ -76,7 +84,7 @@ keepBuild($_, 0) foreach $db->resultset('Builds')->search({ finished => 0 }, { c
|
||||||
# Keep all builds that have been marked as "keep".
|
# Keep all builds that have been marked as "keep".
|
||||||
print STDERR "*** looking for kept builds\n";
|
print STDERR "*** looking for kept builds\n";
|
||||||
my @buildsToKeep = $db->resultset('Builds')->search(
|
my @buildsToKeep = $db->resultset('Builds')->search(
|
||||||
{ finished => 1, keep => 1 }, { order_by => ["project", "jobset", "job", "id"], columns => [ @columns ] });
|
{ finished => 1, keep => 1 }, { order_by => ["jobset_id", "job", "id"], columns => [ @columns ] });
|
||||||
keepBuild($_, 0) foreach @buildsToKeep;
|
keepBuild($_, 0) foreach @buildsToKeep;
|
||||||
|
|
||||||
|
|
||||||
|
|
22
t/scripts/hydra-update-gc-roots/update-gc-roots.t
Normal file
22
t/scripts/hydra-update-gc-roots/update-gc-roots.t
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
use feature 'unicode_strings';
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use Setup;
|
||||||
|
use Test2::V0;
|
||||||
|
|
||||||
|
my $ctx = test_context();
|
||||||
|
my $builds = $ctx->makeAndEvaluateJobset(
|
||||||
|
expression => "one-job.nix",
|
||||||
|
build => 1
|
||||||
|
);
|
||||||
|
|
||||||
|
subtest "Updating GC roots" => sub {
|
||||||
|
my ($res, $stdout, $stderr) = captureStdoutStderr(5, ("hydra-update-gc-roots"));
|
||||||
|
is($res, 0, "hydra-update-gc-roots should exit zero");
|
||||||
|
if ($res != 0) {
|
||||||
|
print "gc roots stdout: $stdout\n";
|
||||||
|
print "gc roots stderr: $stderr";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
done_testing;
|
Loading…
Reference in a new issue