2008-11-10 13:33:12 +00:00
|
|
|
#! @perl@ -w
|
|
|
|
|
|
|
|
use strict;
|
2008-11-11 10:27:36 +00:00
|
|
|
use POSIX qw(dup2);
|
2008-11-10 13:33:12 +00:00
|
|
|
use HydraFrontend::Schema;
|
|
|
|
|
|
|
|
|
|
|
|
my $db = HydraFrontend::Schema->connect("dbi:SQLite:dbname=hydra.sqlite", "", "", {});
|
|
|
|
|
2008-11-11 10:27:36 +00:00
|
|
|
$db->storage->dbh->do("PRAGMA synchronous = OFF;");
|
|
|
|
|
2008-11-10 13:33:12 +00:00
|
|
|
|
|
|
|
# Unlock jobs whose building process has died.
|
|
|
|
$db->txn_do(sub {
|
2008-11-11 12:54:37 +00:00
|
|
|
my @jobs = $db->resultset('Builds')->search(
|
|
|
|
{finished => 0, busy => 1}, {join => 'schedulingInfo'});
|
2008-11-10 13:33:12 +00:00
|
|
|
foreach my $job (@jobs) {
|
2008-11-11 12:54:37 +00:00
|
|
|
print $job, "\n";
|
|
|
|
my $pid = $job->schedulingInfo->locker;
|
2008-11-10 13:33:12 +00:00
|
|
|
if (kill(0, $pid) != 1) { # see if we can signal the process
|
|
|
|
print "job ", $job->id, " pid $pid died, unlocking\n";
|
2008-11-11 12:54:37 +00:00
|
|
|
$job->schedulingInfo->busy(0);
|
|
|
|
$job->schedulingInfo->locker("");
|
|
|
|
$job->schedulingInfo->update;
|
2008-11-10 13:33:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2008-11-11 10:27:36 +00:00
|
|
|
sub checkJobs {
|
2008-11-10 13:33:12 +00:00
|
|
|
print "looking for runnable jobs...\n";
|
|
|
|
|
|
|
|
my $job;
|
|
|
|
|
|
|
|
$db->txn_do(sub {
|
|
|
|
|
2008-11-11 12:54:37 +00:00
|
|
|
my @jobs = $db->resultset('Builds')->search(
|
|
|
|
{finished => 0, busy => 0},
|
|
|
|
{join => 'schedulingInfo', order_by => ["priority", "timestamp"]});
|
2008-11-10 13:33:12 +00:00
|
|
|
|
|
|
|
print "# of available jobs: ", scalar(@jobs), "\n";
|
|
|
|
|
|
|
|
if (scalar @jobs > 0) {
|
|
|
|
$job = $jobs[0];
|
2008-11-11 12:54:37 +00:00
|
|
|
$job->schedulingInfo->busy(1);
|
|
|
|
$job->schedulingInfo->locker($$);
|
|
|
|
$job->schedulingInfo->update;
|
2008-11-10 13:33:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
# Start the job. We need to do this outside the transaction in
|
|
|
|
# case it aborts or something.
|
|
|
|
if (defined $job) {
|
2008-11-11 10:27:36 +00:00
|
|
|
my $id = $job->id;
|
|
|
|
print "starting job $id\n";
|
2008-11-10 13:33:12 +00:00
|
|
|
eval {
|
2008-11-11 10:27:36 +00:00
|
|
|
my $child = fork();
|
|
|
|
die unless defined $child;
|
|
|
|
if ($child == 0) {
|
|
|
|
open LOG, ">logs/$id" or die;
|
|
|
|
POSIX::dup2(fileno(LOG), 1) or die;
|
|
|
|
POSIX::dup2(fileno(LOG), 2) or die;
|
|
|
|
exec("perl", "-IHydraFrontend/lib", "-w",
|
|
|
|
"./build.pl", $id);
|
|
|
|
warn "cannot start job " . $id;
|
|
|
|
_exit(1);
|
|
|
|
}
|
2008-11-10 13:33:12 +00:00
|
|
|
};
|
|
|
|
if ($@) {
|
|
|
|
warn $@;
|
|
|
|
$db->txn_do(sub {
|
2008-11-11 12:54:37 +00:00
|
|
|
$job->schedulingInfo->busy(0);
|
|
|
|
$job->schedulingInfo->locker($$);
|
|
|
|
$job->schedulingInfo->update;
|
2008-11-10 13:33:12 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2008-11-11 10:27:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
eval {
|
|
|
|
checkJobs;
|
|
|
|
};
|
|
|
|
warn $@ if $@;
|
2008-11-10 13:33:12 +00:00
|
|
|
|
|
|
|
print "sleeping...\n";
|
|
|
|
sleep(10);
|
|
|
|
}
|