Add an action to cancel all builds in a jobset eval

This commit is contained in:
Eelco Dolstra
2013-10-04 15:40:43 +02:00
parent 3e54f0a6ab
commit 7818bb75ed
6 changed files with 44 additions and 35 deletions

View File

@ -21,7 +21,8 @@ our @EXPORT = qw(
getEvals getMachines
pathIsInsidePrefix
captureStdoutStderr run grab
getTotalShares);
getTotalShares
cancelBuilds);
sub getHydraHome {
@ -43,11 +44,12 @@ sub getHydraConfig {
# doesn't work.
sub txn_do {
my ($db, $coderef) = @_;
my $res;
while (1) {
eval {
$db->txn_do($coderef);
$res = $db->txn_do($coderef);
};
last if !$@;
return $res if !$@;
die $@ unless $@ =~ "database is locked";
}
}
@ -542,4 +544,21 @@ sub getTotalShares {
}
sub cancelBuilds($$) {
my ($db, $builds) = @_;
return txn_do($db, sub {
$builds = $builds->search({ finished => 0, busy => 0 });
my $n = $builds->count;
my $time = time();
$builds->update(
{ finished => 1,
, iscachedbuild => 0, buildstatus => 4 # = cancelled
, starttime => $time
, stoptime => $time
});
return $n;
});
}
1;