forked from lix-project/hydra
* Don't start more builds concurrently than allowed for each system
type (currently hard-coded at 2).
This commit is contained in:
parent
39f8b6110f
commit
21497f9a47
|
@ -30,33 +30,57 @@ $db->txn_do(sub {
|
||||||
sub checkJobs {
|
sub checkJobs {
|
||||||
print "looking for runnable jobs...\n";
|
print "looking for runnable jobs...\n";
|
||||||
|
|
||||||
my $job;
|
my @jobsStarted;
|
||||||
my $logfile;
|
my $logfile;
|
||||||
|
|
||||||
$db->txn_do(sub {
|
$db->txn_do(sub {
|
||||||
|
|
||||||
my @jobs = $db->resultset('Builds')->search(
|
# Get the system types for the runnable builds.
|
||||||
|
my @systemTypes = $db->resultset('Builds')->search(
|
||||||
{finished => 0, busy => 0},
|
{finished => 0, busy => 0},
|
||||||
{join => 'schedulingInfo', order_by => ["priority", "timestamp"]});
|
{join => 'schedulingInfo', select => [{distinct => 'system'}], as => ['system']});
|
||||||
|
|
||||||
print "# of available jobs: ", scalar(@jobs), "\n";
|
# For each system type, select up to the maximum number of
|
||||||
|
# concurrent build for that system type. Choose the highest
|
||||||
|
# priority builds first, then the oldest builds.
|
||||||
|
foreach my $system (@systemTypes) {
|
||||||
|
# How many builds are already currently executing for this
|
||||||
|
# system type?
|
||||||
|
my $nrActive = $db->resultset('Builds')->search(
|
||||||
|
{finished => 0, busy => 1, system => $system->system},
|
||||||
|
{join => 'schedulingInfo'})->count;
|
||||||
|
|
||||||
if (scalar @jobs > 0) {
|
# How many extra builds can we start?
|
||||||
$job = $jobs[0];
|
my $maxActive = 2;
|
||||||
$logfile = getcwd . "/logs/" . $job->id;
|
my $extraAllowed = $maxActive - $nrActive;
|
||||||
unlink $logfile;
|
$extraAllowed = 0 if $extraAllowed < 0;
|
||||||
$job->schedulingInfo->busy(1);
|
|
||||||
$job->schedulingInfo->locker($$);
|
# Select the highest-priority builds to start.
|
||||||
$job->schedulingInfo->logfile($logfile);
|
my @jobs = $extraAllowed == 0 ? () : $db->resultset('Builds')->search(
|
||||||
$job->schedulingInfo->update;
|
{ finished => 0, busy => 0, system => $system->system },
|
||||||
$job->buildsteps->delete_all;
|
{ join => 'schedulingInfo', order_by => ["priority DESC", "timestamp"],
|
||||||
|
rows => $extraAllowed });
|
||||||
|
|
||||||
|
print "system type `", $system->system,
|
||||||
|
"': $nrActive active, $maxActive allowed, ",
|
||||||
|
"starting ", scalar(@jobs), " builds\n";
|
||||||
|
|
||||||
|
foreach my $job (@jobs) {
|
||||||
|
$logfile = getcwd . "/logs/" . $job->id;
|
||||||
|
unlink $logfile;
|
||||||
|
$job->schedulingInfo->busy(1);
|
||||||
|
$job->schedulingInfo->locker($$);
|
||||||
|
$job->schedulingInfo->logfile($logfile);
|
||||||
|
$job->schedulingInfo->update;
|
||||||
|
$job->buildsteps->delete_all;
|
||||||
|
push @jobsStarted, $job;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
# Start the job. We need to do this outside the transaction in
|
# Actually start the builds we just selected. We need to do this
|
||||||
# case it aborts or something.
|
# outside the transaction in case it aborts or something.
|
||||||
if (defined $job) {
|
foreach my $job (@jobsStarted) {
|
||||||
my $id = $job->id;
|
my $id = $job->id;
|
||||||
print "starting job $id\n";
|
print "starting job $id\n";
|
||||||
eval {
|
eval {
|
||||||
|
@ -69,7 +93,7 @@ sub checkJobs {
|
||||||
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 job " . $id;
|
||||||
_exit(1);
|
POSIX::_exit(1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if ($@) {
|
if ($@) {
|
||||||
|
|
Loading…
Reference in a new issue