diff --git a/src/script/hydra-update-gc-roots b/src/script/hydra-update-gc-roots index b8ddf971..91d6393b 100755 --- a/src/script/hydra-update-gc-roots +++ b/src/script/hydra-update-gc-roots @@ -25,7 +25,7 @@ sub addRoot { 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)" } ); @@ -35,8 +35,16 @@ sub keepBuild { my ($build, $keepFailedDrvs) = @_; return if defined $seenBuilds{$build->id}; $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, " (", - $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, "; ", strftime("%Y-%m-%d %H:%M:%S", localtime($build->timestamp)), ")\n"; 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". print STDERR "*** looking for kept builds\n"; 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; diff --git a/t/scripts/hydra-update-gc-roots/update-gc-roots.t b/t/scripts/hydra-update-gc-roots/update-gc-roots.t new file mode 100644 index 00000000..9729e066 --- /dev/null +++ b/t/scripts/hydra-update-gc-roots/update-gc-roots.t @@ -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;