* Fix the terminology.

This commit is contained in:
Eelco Dolstra 2008-11-28 11:16:53 +00:00
parent 88c34fb6c7
commit b97c946f8e

View file

@ -11,28 +11,28 @@ my $db = Hydra::Schema->connect("dbi:SQLite:dbname=hydra.sqlite", "", "", {});
$db->storage->dbh->do("PRAGMA synchronous = OFF;"); $db->storage->dbh->do("PRAGMA synchronous = OFF;");
sub unlockDeadJobs { sub unlockDeadBuilds {
# Unlock jobs whose building process has died. # Unlock builds whose building process has died.
$db->txn_do(sub { $db->txn_do(sub {
my @jobs = $db->resultset('Builds')->search( my @builds = $db->resultset('Builds')->search(
{finished => 0, busy => 1}, {join => 'schedulingInfo'}); {finished => 0, busy => 1}, {join => 'schedulingInfo'});
foreach my $job (@jobs) { foreach my $build (@builds) {
my $pid = $job->schedulingInfo->locker; my $pid = $build->schedulingInfo->locker;
if (kill(0, $pid) != 1) { # see if we can signal the process if (kill(0, $pid) != 1) { # see if we can signal the process
print "job ", $job->id, " pid $pid died, unlocking\n"; print "build ", $build->id, " pid $pid died, unlocking\n";
$job->schedulingInfo->busy(0); $build->schedulingInfo->busy(0);
$job->schedulingInfo->locker(""); $build->schedulingInfo->locker("");
$job->schedulingInfo->update; $build->schedulingInfo->update;
} }
} }
}); });
} }
sub checkJobs { sub checkBuilds {
print "looking for runnable jobs...\n"; print "looking for runnable builds...\n";
my @jobsStarted; my @buildsStarted;
$db->txn_do(sub { $db->txn_do(sub {
@ -58,36 +58,36 @@ sub checkJobs {
$extraAllowed = 0 if $extraAllowed < 0; $extraAllowed = 0 if $extraAllowed < 0;
# Select the highest-priority builds to start. # Select the highest-priority builds to start.
my @jobs = $extraAllowed == 0 ? () : $db->resultset('Builds')->search( my @builds = $extraAllowed == 0 ? () : $db->resultset('Builds')->search(
{ finished => 0, busy => 0, system => $system->system }, { finished => 0, busy => 0, system => $system->system },
{ join => 'schedulingInfo', order_by => ["priority DESC", "timestamp"], { join => 'schedulingInfo', order_by => ["priority DESC", "timestamp"],
rows => $extraAllowed }); rows => $extraAllowed });
print "system type `", $system->system, print "system type `", $system->system,
"': $nrActive active, $maxConcurrent allowed, ", "': $nrActive active, $maxConcurrent allowed, ",
"starting ", scalar(@jobs), " builds\n"; "starting ", scalar(@builds), " builds\n";
foreach my $job (@jobs) { foreach my $build (@builds) {
my $logfile = getcwd . "/logs/" . $job->id; my $logfile = getcwd . "/logs/" . $build->id;
unlink($logfile); unlink($logfile);
$job->schedulingInfo->busy(1); $build->schedulingInfo->busy(1);
$job->schedulingInfo->locker($$); $build->schedulingInfo->locker($$);
$job->schedulingInfo->logfile($logfile); $build->schedulingInfo->logfile($logfile);
$job->schedulingInfo->starttime(time); $build->schedulingInfo->starttime(time);
$job->schedulingInfo->update; $build->schedulingInfo->update;
$job->buildsteps->delete_all; $build->buildsteps->delete_all;
push @jobsStarted, $job; push @buildsStarted, $build;
} }
} }
}); });
# Actually start the builds we just selected. We need to do this # Actually start the builds we just selected. We need to do this
# outside the transaction in case it aborts or something. # outside the transaction in case it aborts or something.
foreach my $job (@jobsStarted) { foreach my $build (@buildsStarted) {
my $id = $job->id; my $id = $build->id;
print "starting job $id (", $job->project->name, ":", $job->attrname, ") on ", $job->system, "\n"; print "starting build $id (", $build->project->name, ":", $build->attrname, ") on ", $build->system, "\n";
eval { eval {
my $logfile = $job->schedulingInfo->logfile; my $logfile = $build->schedulingInfo->logfile;
my $child = fork(); my $child = fork();
die unless defined $child; die unless defined $child;
if ($child == 0) { if ($child == 0) {
@ -96,16 +96,16 @@ sub checkJobs {
POSIX::dup2(fileno(LOG), 2) or die; POSIX::dup2(fileno(LOG), 2) or die;
exec("perl", "-IHydra/lib", "-w", exec("perl", "-IHydra/lib", "-w",
"./Hydra/programs/Build.pl", $id); "./Hydra/programs/Build.pl", $id);
warn "cannot start job " . $id; warn "cannot start build " . $id;
POSIX::_exit(1); POSIX::_exit(1);
} }
}; };
if ($@) { if ($@) {
warn $@; warn $@;
$db->txn_do(sub { $db->txn_do(sub {
$job->schedulingInfo->busy(0); $build->schedulingInfo->busy(0);
$job->schedulingInfo->locker($$); $build->schedulingInfo->locker($$);
$job->schedulingInfo->update; $build->schedulingInfo->update;
}); });
} }
} }
@ -114,8 +114,8 @@ sub checkJobs {
while (1) { while (1) {
eval { eval {
unlockDeadJobs; unlockDeadBuilds;
checkJobs; checkBuilds;
}; };
warn $@ if $@; warn $@ if $@;