Skip to content

Commit

Permalink
Keep the most recent successful build of current jobs
Browse files Browse the repository at this point in the history
Fixes #140.
  • Loading branch information
edolstra committed Jun 11, 2015
1 parent a91cbef commit 9989a90
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/script/hydra-update-gc-roots
Expand Up @@ -24,8 +24,12 @@ sub addRoot {

my @columns = ( "id", "project", "jobset", "job", "system", "finished", "drvpath", "timestamp", "buildstatus" );

my %seenBuilds;

sub keepBuild {
my ($build, $keepFailedDrvs) = @_;
return if defined $seenBuilds{$build->id};
$seenBuilds{$build->id} = 1;
print STDERR " keeping ", ($build->finished ? "" : "scheduled "), "build ", $build->id, " (",
$build->get_column('project'), ":", $build->get_column('jobset'), ":", $build->get_column('job'), "; ",
$build->system, "; ",
Expand Down Expand Up @@ -108,10 +112,33 @@ foreach my $project ($db->resultset('Projects')->search({}, { order_by => ["name
, order_by => "id desc", rows => $keepnr });
}

# Note: we also keep the derivations of failed builds so that
# they can be restarted.
keepBuild($_, 1) foreach $jobset->builds->search(
{ id => { -in => $db->resultset('JobsetEvalMembers')->search({ eval => { -in => [@evals] } }, { select => "build" })->as_query }
, finished => 1
},
{ order_by => ["job", "id"], columns => [ @columns ] });

print STDERR "*** looking for the most recent successful builds of current jobs in ",
$project->name, ":", $jobset->name, "\n";

# Keep the most recently succeeded build of a current job. Oh
# I really need to stop using DBIx::Class.

This comment has been minimized.

Copy link
@nckx

nckx Jun 11, 2015

Member

What's evil about it?

This comment has been minimized.

Copy link
@shlevy

shlevy Jun 11, 2015

Member

It's perl? ducks

This comment has been minimized.

Copy link
@edolstra

edolstra Jun 11, 2015

Author Member

It's not evil, it's just inconvenient that I had a relatively short SQL query and then I had to spend half an hour figuring out how to express it using DBIx::Class.

This comment has been minimized.

Copy link
@grahamc

grahamc Feb 25, 2021

Member
keepBuild($_, 1) foreach $jobset->builds->search(
{ id => { -in => $jobset->builds->search(
{ finished => 1
, buildstatus => [0, 6]
, job => { -in => $jobset->builds->search(
{ eval => { -in => [@evals] } },
{ select => "job", distinct => 1, join => "jobsetevalmembers" }
)->as_query }
},
{ group_by => 'job'
, select => [ { max => 'id', -as => 'm' } ]
})->as_query }
},
{ columns => [ @columns ] });
}
}

Expand Down

1 comment on commit 9989a90

@shlevy
Copy link
Member

@shlevy shlevy commented on 9989a90 Jun 11, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍻

Please sign in to comment.