2015-06-22 22:14:49 +00:00
|
|
|
|
#! /run/current-system/sw/bin/perl
|
2008-10-10 16:05:05 +00:00
|
|
|
|
|
|
|
|
|
use strict;
|
2013-09-25 13:51:03 +00:00
|
|
|
|
use utf8;
|
2008-11-25 11:09:15 +00:00
|
|
|
|
use Hydra::Schema;
|
2013-05-25 19:36:58 +00:00
|
|
|
|
use Hydra::Plugin;
|
2008-11-28 14:36:04 +00:00
|
|
|
|
use Hydra::Helper::Nix;
|
2009-10-26 15:39:14 +00:00
|
|
|
|
use Hydra::Helper::AddBuilds;
|
2014-11-19 13:44:04 +00:00
|
|
|
|
use Hydra::Helper::Email;
|
2012-03-13 11:10:19 +00:00
|
|
|
|
use Hydra::Model::DB;
|
2009-11-17 13:55:22 +00:00
|
|
|
|
use Digest::SHA qw(sha256_hex);
|
2009-12-18 12:07:45 +00:00
|
|
|
|
use Config::General;
|
2010-01-19 14:15:31 +00:00
|
|
|
|
use Data::Dump qw(dump);
|
2014-11-19 13:44:04 +00:00
|
|
|
|
use Try::Tiny;
|
2008-10-28 10:18:03 +00:00
|
|
|
|
|
2009-04-22 22:59:54 +00:00
|
|
|
|
STDOUT->autoflush();
|
2014-11-19 13:44:04 +00:00
|
|
|
|
STDERR->autoflush(1);
|
|
|
|
|
binmode STDERR, ":encoding(utf8)";
|
2009-04-22 22:59:54 +00:00
|
|
|
|
|
2012-03-13 11:10:19 +00:00
|
|
|
|
my $db = Hydra::Model::DB->new();
|
2013-01-22 12:19:28 +00:00
|
|
|
|
my $config = getHydraConfig();
|
2008-11-05 04:52:52 +00:00
|
|
|
|
|
2013-07-02 11:54:18 +00:00
|
|
|
|
my $plugins = [Hydra::Plugin->instantiate(db => $db, config => $config)];
|
2013-05-25 19:36:58 +00:00
|
|
|
|
|
2013-02-25 17:47:54 +00:00
|
|
|
|
# Don't check a jobset more than once every five minutes.
|
2013-02-25 20:04:10 +00:00
|
|
|
|
my $minCheckInterval = 5 * 60;
|
2013-02-25 17:47:54 +00:00
|
|
|
|
|
2015-04-09 15:35:04 +00:00
|
|
|
|
my $dryRun = defined $ENV{'HYDRA_DRY_RUN'};
|
2013-02-25 17:47:54 +00:00
|
|
|
|
|
2010-03-05 15:41:10 +00:00
|
|
|
|
|
2009-03-09 13:04:46 +00:00
|
|
|
|
sub fetchInputs {
|
2009-03-09 13:58:43 +00:00
|
|
|
|
my ($project, $jobset, $inputInfo) = @_;
|
2009-03-09 13:04:46 +00:00
|
|
|
|
foreach my $input ($jobset->jobsetinputs->all) {
|
|
|
|
|
foreach my $alt ($input->jobsetinputalts->all) {
|
2013-05-25 19:36:58 +00:00
|
|
|
|
push @{$$inputInfo{$input->name}}, $_
|
2013-10-08 18:47:24 +00:00
|
|
|
|
foreach fetchInput($plugins, $db, $project, $jobset, $input->name, $input->type, $alt->value, $input->emailresponsible);
|
2009-03-09 13:04:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-11-25 13:27:57 +00:00
|
|
|
|
sub setJobsetError {
|
|
|
|
|
my ($jobset, $errorMsg) = @_;
|
2013-09-24 16:01:40 +00:00
|
|
|
|
my $prevError = $jobset->errormsg;
|
|
|
|
|
|
2008-11-25 13:27:57 +00:00
|
|
|
|
eval {
|
2009-04-22 22:43:04 +00:00
|
|
|
|
txn_do($db, sub {
|
2013-09-25 14:21:16 +00:00
|
|
|
|
$jobset->update({ errormsg => $errorMsg, errortime => time, fetcherrormsg => undef });
|
2008-11-25 13:27:57 +00:00
|
|
|
|
});
|
|
|
|
|
};
|
2014-11-19 13:44:04 +00:00
|
|
|
|
if (defined $errorMsg && $errorMsg ne ($prevError // "") || $ENV{'HYDRA_MAIL_TEST'}) {
|
2013-09-24 16:01:40 +00:00
|
|
|
|
sendJobsetErrorNotification($jobset, $errorMsg);
|
|
|
|
|
}
|
2008-11-25 13:27:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-04-03 10:10:45 +00:00
|
|
|
|
|
2009-12-18 12:07:45 +00:00
|
|
|
|
sub sendJobsetErrorNotification() {
|
|
|
|
|
my ($jobset, $errorMsg) = @_;
|
|
|
|
|
|
2014-11-19 13:44:04 +00:00
|
|
|
|
chomp $errorMsg;
|
|
|
|
|
|
2009-12-18 12:07:45 +00:00
|
|
|
|
return if $jobset->project->owner->emailonerror == 0;
|
2013-01-22 12:19:28 +00:00
|
|
|
|
return if $errorMsg eq "";
|
2009-12-18 12:07:45 +00:00
|
|
|
|
|
|
|
|
|
my $projectName = $jobset->project->name;
|
|
|
|
|
my $jobsetName = $jobset->name;
|
|
|
|
|
my $body = "Hi,\n"
|
|
|
|
|
. "\n"
|
2014-11-19 13:44:04 +00:00
|
|
|
|
. "This is to let you know that evaluation of the Hydra jobset ‘$projectName:$jobsetName’\n"
|
2009-12-18 12:07:45 +00:00
|
|
|
|
. "resulted in the following error:\n"
|
|
|
|
|
. "\n"
|
|
|
|
|
. "$errorMsg"
|
|
|
|
|
. "\n"
|
|
|
|
|
. "Regards,\n\nThe Hydra build daemon.\n";
|
|
|
|
|
|
2014-11-19 13:44:04 +00:00
|
|
|
|
try {
|
|
|
|
|
sendEmail(
|
|
|
|
|
$config,
|
|
|
|
|
$jobset->project->owner->emailaddress,
|
|
|
|
|
"Hydra $projectName:$jobsetName evaluation error",
|
|
|
|
|
$body,
|
|
|
|
|
[ 'X-Hydra-Project' => $projectName
|
|
|
|
|
, 'X-Hydra-Jobset' => $jobsetName
|
|
|
|
|
]);
|
|
|
|
|
} catch {
|
|
|
|
|
warn "error sending email: $_\n";
|
|
|
|
|
};
|
2009-12-18 12:07:45 +00:00
|
|
|
|
}
|
2008-11-25 13:27:57 +00:00
|
|
|
|
|
2012-03-07 17:48:10 +00:00
|
|
|
|
|
2009-04-23 15:40:36 +00:00
|
|
|
|
sub permute {
|
|
|
|
|
my @list = @_;
|
|
|
|
|
for (my $n = scalar @list - 1; $n > 0; $n--) {
|
2013-01-22 12:19:28 +00:00
|
|
|
|
my $k = int(rand($n + 1)); # 0 <= $k <= $n
|
2009-04-23 15:40:36 +00:00
|
|
|
|
@list[$n, $k] = @list[$k, $n];
|
|
|
|
|
}
|
|
|
|
|
return @list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-02-25 17:47:54 +00:00
|
|
|
|
sub checkJobsetWrapped {
|
|
|
|
|
my ($jobset) = @_;
|
|
|
|
|
my $project = $jobset->project;
|
2008-11-07 14:51:44 +00:00
|
|
|
|
my $inputInfo = {};
|
2012-08-16 17:07:04 +00:00
|
|
|
|
my $exprType = $jobset->nixexprpath =~ /.scm$/ ? "guile" : "nix";
|
2013-01-22 12:19:28 +00:00
|
|
|
|
|
2009-03-09 13:04:46 +00:00
|
|
|
|
# Fetch all values for all inputs.
|
2010-03-05 15:41:10 +00:00
|
|
|
|
my $checkoutStart = time;
|
2013-09-25 14:21:16 +00:00
|
|
|
|
eval {
|
|
|
|
|
fetchInputs($project, $jobset, $inputInfo);
|
|
|
|
|
};
|
|
|
|
|
if ($@) {
|
|
|
|
|
my $msg = $@;
|
|
|
|
|
print STDERR $msg;
|
|
|
|
|
txn_do($db, sub {
|
2015-04-09 15:35:04 +00:00
|
|
|
|
$jobset->update({ lastcheckedtime => time, fetcherrormsg => $msg }) if !$dryRun;
|
2013-09-25 14:21:16 +00:00
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-03-05 15:41:10 +00:00
|
|
|
|
my $checkoutStop = time;
|
2008-11-07 14:51:44 +00:00
|
|
|
|
|
2011-11-30 17:13:35 +00:00
|
|
|
|
# Hash the arguments to hydra-eval-jobs and check the
|
2012-03-07 17:48:10 +00:00
|
|
|
|
# JobsetInputHashes to see if the previous evaluation had the same
|
2009-11-17 13:55:22 +00:00
|
|
|
|
# inputs. If so, bail out.
|
2012-08-16 17:07:04 +00:00
|
|
|
|
my @args = ($jobset->nixexprinput, $jobset->nixexprpath, inputsToArgs($inputInfo, $exprType));
|
2009-11-17 13:55:22 +00:00
|
|
|
|
my $argsHash = sha256_hex("@args");
|
2012-03-12 20:13:28 +00:00
|
|
|
|
my $prevEval = getPrevJobsetEval($db, $jobset, 0);
|
2015-04-09 15:35:04 +00:00
|
|
|
|
if (defined $prevEval && $prevEval->hash eq $argsHash && !$dryRun) {
|
2012-03-07 17:48:10 +00:00
|
|
|
|
print STDERR " jobset is unchanged, skipping\n";
|
2009-11-17 13:55:22 +00:00
|
|
|
|
txn_do($db, sub {
|
2013-09-25 14:21:16 +00:00
|
|
|
|
$jobset->update({ lastcheckedtime => time, fetcherrormsg => undef });
|
2009-11-17 13:55:22 +00:00
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-01-22 12:19:28 +00:00
|
|
|
|
|
2009-03-09 13:04:46 +00:00
|
|
|
|
# Evaluate the job expression.
|
2010-03-05 15:41:10 +00:00
|
|
|
|
my $evalStart = time;
|
2014-09-29 22:20:54 +00:00
|
|
|
|
my ($jobs, $nixExprInput) = evalJobs($inputInfo, $exprType, $jobset->nixexprinput, $jobset->nixexprpath);
|
2010-03-05 15:41:10 +00:00
|
|
|
|
my $evalStop = time;
|
2009-03-09 15:16:11 +00:00
|
|
|
|
|
2015-04-09 15:35:04 +00:00
|
|
|
|
if ($dryRun) {
|
|
|
|
|
foreach my $name (keys %{$jobs}) {
|
|
|
|
|
my $job = $jobs->{$name};
|
|
|
|
|
if (defined $job->{drvPath}) {
|
|
|
|
|
print STDERR "good job $name: $job->{drvPath}\n";
|
|
|
|
|
} else {
|
|
|
|
|
print STDERR "failed job $name: $job->{error}\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-29 22:20:54 +00:00
|
|
|
|
$jobs->{$_}->{jobName} = $_ for keys %{$jobs};
|
|
|
|
|
|
2012-04-02 15:56:29 +00:00
|
|
|
|
my $jobOutPathMap = {};
|
|
|
|
|
|
2009-04-22 22:43:04 +00:00
|
|
|
|
txn_do($db, sub {
|
2013-01-22 12:19:28 +00:00
|
|
|
|
|
2012-03-12 19:28:44 +00:00
|
|
|
|
my $prevEval = getPrevJobsetEval($db, $jobset, 1);
|
|
|
|
|
|
2012-03-07 17:48:10 +00:00
|
|
|
|
# Clear the "current" flag on all builds. Since we're in a
|
|
|
|
|
# transaction this will only become visible after the new
|
|
|
|
|
# current builds have been added.
|
|
|
|
|
$jobset->builds->search({iscurrent => 1})->update({iscurrent => 0});
|
|
|
|
|
|
2010-03-05 15:41:10 +00:00
|
|
|
|
# Schedule each successfully evaluated job.
|
2013-08-13 23:59:29 +00:00
|
|
|
|
my %buildMap;
|
2014-09-29 22:20:54 +00:00
|
|
|
|
foreach my $job (permute(values %{$jobs})) {
|
|
|
|
|
next if defined $job->{error};
|
2014-09-29 22:29:36 +00:00
|
|
|
|
#print STDERR "considering job " . $project->name, ":", $jobset->name, ":", $job->{jobName} . "\n";
|
2013-08-13 23:59:29 +00:00
|
|
|
|
checkBuild($db, $jobset, $inputInfo, $nixExprInput, $job, \%buildMap, $prevEval, $jobOutPathMap, $plugins);
|
2010-03-05 15:41:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-01 18:24:52 +00:00
|
|
|
|
# Have any builds been added or removed since last time?
|
|
|
|
|
my $jobsetChanged =
|
|
|
|
|
(scalar(grep { $_->{new} } values(%buildMap)) > 0)
|
|
|
|
|
|| (defined $prevEval && $prevEval->jobsetevalmembers->count != scalar(keys %buildMap));
|
2010-03-05 15:41:10 +00:00
|
|
|
|
|
|
|
|
|
my $ev = $jobset->jobsetevals->create(
|
|
|
|
|
{ hash => $argsHash
|
|
|
|
|
, timestamp => time
|
|
|
|
|
, checkouttime => abs($checkoutStop - $checkoutStart)
|
|
|
|
|
, evaltime => abs($evalStop - $evalStart)
|
2013-11-01 18:24:52 +00:00
|
|
|
|
, hasnewbuilds => $jobsetChanged ? 1 : 0
|
|
|
|
|
, nrbuilds => $jobsetChanged ? scalar(keys %buildMap) : undef
|
2010-03-05 15:41:10 +00:00
|
|
|
|
});
|
|
|
|
|
|
2013-11-01 18:24:52 +00:00
|
|
|
|
if ($jobsetChanged) {
|
2013-08-13 23:59:29 +00:00
|
|
|
|
# Create JobsetEvalMembers mappings.
|
|
|
|
|
while (my ($id, $x) = each %buildMap) {
|
|
|
|
|
$ev->jobsetevalmembers->create({ build => $id, isnew => $x->{new} });
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-27 09:48:02 +00:00
|
|
|
|
# Create AggregateConstituents mappings. Since there can
|
|
|
|
|
# be jobs that alias each other, if there are multiple
|
|
|
|
|
# builds for the same derivation, pick the one with the
|
|
|
|
|
# shortest name.
|
|
|
|
|
my %drvPathToId;
|
|
|
|
|
while (my ($id, $x) = each %buildMap) {
|
|
|
|
|
my $y = $drvPathToId{$x->{drvPath}};
|
|
|
|
|
if (defined $y) {
|
|
|
|
|
next if length $x->{jobName} > length $y->{jobName};
|
|
|
|
|
next if length $x->{jobName} == length $y->{jobName} && $x->{jobName} ge $y->{jobName};
|
|
|
|
|
}
|
|
|
|
|
$drvPathToId{$x->{drvPath}} = $x;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-01 13:34:05 +00:00
|
|
|
|
foreach my $job (values %{$jobs}) {
|
2013-08-15 00:33:10 +00:00
|
|
|
|
next unless $job->{constituents};
|
2013-08-27 09:48:02 +00:00
|
|
|
|
my $x = $drvPathToId{$job->{drvPath}} or die;
|
2013-08-15 00:33:10 +00:00
|
|
|
|
foreach my $drvPath (split / /, $job->{constituents}) {
|
|
|
|
|
my $constituent = $drvPathToId{$drvPath};
|
|
|
|
|
if (defined $constituent) {
|
2013-08-27 09:48:02 +00:00
|
|
|
|
$db->resultset('AggregateConstituents')->update_or_create({aggregate => $x->{id}, constituent => $constituent->{id}});
|
2013-08-13 23:59:29 +00:00
|
|
|
|
} else {
|
2013-08-15 00:33:10 +00:00
|
|
|
|
warn "aggregate job ‘$job->{jobName}’ has a constituent ‘$drvPath’ that doesn't correspond to a Hydra build\n";
|
2013-08-13 23:59:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-05 15:41:10 +00:00
|
|
|
|
}
|
2013-01-22 12:19:28 +00:00
|
|
|
|
|
2012-04-15 18:36:36 +00:00
|
|
|
|
foreach my $name (keys %{$inputInfo}) {
|
|
|
|
|
for (my $n = 0; $n < scalar(@{$inputInfo->{$name}}); $n++) {
|
|
|
|
|
my $input = $inputInfo->{$name}->[$n];
|
|
|
|
|
$ev->jobsetevalinputs->create(
|
|
|
|
|
{ name => $name
|
|
|
|
|
, altnr => $n
|
|
|
|
|
, type => $input->{type}
|
|
|
|
|
, uri => $input->{uri}
|
|
|
|
|
, revision => $input->{revision}
|
|
|
|
|
, value => $input->{value}
|
|
|
|
|
, dependency => $input->{id}
|
|
|
|
|
, path => $input->{storePath} || "" # !!! temporary hack
|
|
|
|
|
, sha256hash => $input->{sha256hash}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-01-22 12:19:28 +00:00
|
|
|
|
|
2012-03-12 19:28:44 +00:00
|
|
|
|
print STDERR " created new eval ", $ev->id, "\n";
|
2012-03-13 12:09:10 +00:00
|
|
|
|
$ev->builds->update({iscurrent => 1});
|
2015-06-26 18:59:14 +00:00
|
|
|
|
|
|
|
|
|
$db->storage->dbh->do("notify builds_added");
|
2012-03-12 19:28:44 +00:00
|
|
|
|
} else {
|
|
|
|
|
print STDERR " created cached eval ", $ev->id, "\n";
|
2012-04-17 10:32:44 +00:00
|
|
|
|
$prevEval->builds->update({iscurrent => 1}) if defined $prevEval;
|
2010-03-05 15:41:10 +00:00
|
|
|
|
}
|
2013-10-11 10:01:52 +00:00
|
|
|
|
|
|
|
|
|
# If this is a one-shot jobset, disable it now.
|
|
|
|
|
$jobset->update({ enabled => 0 }) if $jobset->enabled == 2;
|
2014-09-29 17:46:11 +00:00
|
|
|
|
|
|
|
|
|
$jobset->update({ lastcheckedtime => time });
|
2009-10-02 16:06:28 +00:00
|
|
|
|
});
|
2013-01-22 12:19:28 +00:00
|
|
|
|
|
2012-03-07 17:48:10 +00:00
|
|
|
|
# Store the error messages for jobs that failed to evaluate.
|
2014-09-29 22:20:54 +00:00
|
|
|
|
my $msg = "";
|
|
|
|
|
foreach my $job (values %{$jobs}) {
|
|
|
|
|
next unless defined $job->{error};
|
2013-09-25 13:51:03 +00:00
|
|
|
|
$msg .=
|
2014-09-29 22:20:54 +00:00
|
|
|
|
($job->{jobName} ne "" ? "in job ‘$job->{jobName}’" : "at top-level") .
|
|
|
|
|
":\n" . $job->{error} . "\n\n";
|
2009-03-09 15:16:11 +00:00
|
|
|
|
}
|
2010-01-12 08:39:30 +00:00
|
|
|
|
setJobsetError($jobset, $msg);
|
2008-11-04 18:23:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-02-25 17:47:54 +00:00
|
|
|
|
sub checkJobset {
|
|
|
|
|
my ($jobset) = @_;
|
2013-01-22 12:19:28 +00:00
|
|
|
|
|
2013-02-25 17:47:54 +00:00
|
|
|
|
print STDERR "considering jobset ", $jobset->project->name, ":", $jobset->name,
|
2013-02-25 19:31:49 +00:00
|
|
|
|
$jobset->lastcheckedtime
|
|
|
|
|
? " (last checked " . (time() - $jobset->lastcheckedtime) . "s ago)\n"
|
|
|
|
|
: " (never checked)\n";
|
2013-01-22 12:19:28 +00:00
|
|
|
|
|
2013-02-25 20:04:10 +00:00
|
|
|
|
my $triggerTime = $jobset->triggertime;
|
|
|
|
|
|
2009-03-20 14:50:09 +00:00
|
|
|
|
eval {
|
2013-02-25 17:47:54 +00:00
|
|
|
|
checkJobsetWrapped($jobset);
|
2009-03-20 14:50:09 +00:00
|
|
|
|
};
|
2013-01-22 12:19:28 +00:00
|
|
|
|
|
2013-11-27 19:29:05 +00:00
|
|
|
|
my $failed = 0;
|
2009-03-20 14:50:09 +00:00
|
|
|
|
if ($@) {
|
|
|
|
|
my $msg = $@;
|
2013-09-25 14:21:16 +00:00
|
|
|
|
print STDERR $msg;
|
2009-04-22 22:43:04 +00:00
|
|
|
|
txn_do($db, sub {
|
2009-03-20 14:50:09 +00:00
|
|
|
|
$jobset->update({lastcheckedtime => time});
|
2010-01-12 08:39:30 +00:00
|
|
|
|
setJobsetError($jobset, $msg);
|
2015-04-09 15:35:04 +00:00
|
|
|
|
}) if !$dryRun;
|
2013-11-27 19:29:05 +00:00
|
|
|
|
$failed = 1;
|
2009-03-20 14:50:09 +00:00
|
|
|
|
}
|
2013-02-25 20:04:10 +00:00
|
|
|
|
|
|
|
|
|
if (defined $triggerTime) {
|
|
|
|
|
txn_do($db, sub {
|
|
|
|
|
# Only clear the trigger time if the jobset hasn't been
|
|
|
|
|
# triggered in the meantime. In that case, we need to
|
|
|
|
|
# evaluate again.
|
|
|
|
|
my $new = $jobset->get_from_storage();
|
|
|
|
|
$jobset->update({ triggertime => undef })
|
|
|
|
|
if $new->triggertime == $triggerTime;
|
2015-04-09 15:35:04 +00:00
|
|
|
|
}) if !$dryRun;
|
2013-02-25 20:04:10 +00:00
|
|
|
|
}
|
2015-04-09 15:35:04 +00:00
|
|
|
|
|
2013-11-27 19:29:05 +00:00
|
|
|
|
return $failed;
|
2009-03-20 14:50:09 +00:00
|
|
|
|
}
|
2008-11-04 18:23:28 +00:00
|
|
|
|
|
2009-03-20 14:50:09 +00:00
|
|
|
|
|
2013-02-25 17:47:54 +00:00
|
|
|
|
sub checkSomeJobset {
|
2013-02-25 20:04:10 +00:00
|
|
|
|
# If any jobset has been triggered by a push, check it.
|
2013-02-25 17:47:54 +00:00
|
|
|
|
my ($jobset) = $db->resultset('Jobsets')->search(
|
2013-05-02 15:32:25 +00:00
|
|
|
|
{ 'triggertime' => { '!=', undef },
|
2013-02-25 20:04:10 +00:00
|
|
|
|
, -or => [ 'lastcheckedtime' => undef, 'lastcheckedtime' => { '<', time() - $minCheckInterval } ] },
|
|
|
|
|
{ join => 'project', order_by => [ 'triggertime' ], rows => 1 });
|
|
|
|
|
|
|
|
|
|
# Otherwise, check the jobset that hasn't been checked for the
|
2013-05-02 15:51:38 +00:00
|
|
|
|
# longest time (but don't check more often than the jobset's
|
|
|
|
|
# minimal check interval).
|
2013-02-25 20:04:10 +00:00
|
|
|
|
($jobset) = $db->resultset('Jobsets')->search(
|
2013-10-11 10:01:52 +00:00
|
|
|
|
{ 'project.enabled' => 1, 'me.enabled' => { '!=' => 0 },
|
2013-05-02 15:51:38 +00:00
|
|
|
|
, 'checkinterval' => { '!=', 0 }
|
|
|
|
|
, -or => [ 'lastcheckedtime' => undef, 'lastcheckedtime' => { '<', \ (time() . " - me.checkinterval") } ] },
|
2013-02-25 20:04:10 +00:00
|
|
|
|
{ join => 'project', order_by => [ 'lastcheckedtime nulls first' ], rows => 1 })
|
|
|
|
|
unless defined $jobset;
|
2013-02-25 17:47:54 +00:00
|
|
|
|
|
|
|
|
|
return 0 unless defined $jobset;
|
|
|
|
|
|
2013-09-21 15:49:27 +00:00
|
|
|
|
return system($0, $jobset->project->name, $jobset->name) == 0;
|
2008-11-04 18:23:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-03-05 12:32:14 +00:00
|
|
|
|
if (scalar @ARGV == 2) {
|
|
|
|
|
my $projectName = $ARGV[0];
|
|
|
|
|
my $jobsetName = $ARGV[1];
|
2015-04-14 13:16:24 +00:00
|
|
|
|
my $jobset = $db->resultset('Jobsets')->find($projectName, $jobsetName) or die "$0: specified jobset does not exist\n";
|
2013-11-27 19:29:05 +00:00
|
|
|
|
exit checkJobset($jobset);
|
2009-03-05 12:32:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-11-11 10:27:36 +00:00
|
|
|
|
while (1) {
|
2009-03-23 01:13:37 +00:00
|
|
|
|
eval {
|
2013-02-25 17:47:54 +00:00
|
|
|
|
if (checkSomeJobset) {
|
|
|
|
|
# Just so we don't go completely crazy if lastcheckedtime
|
|
|
|
|
# isn't updated properly.
|
|
|
|
|
sleep 1;
|
|
|
|
|
} else {
|
2013-03-23 12:31:28 +00:00
|
|
|
|
# print STDERR "sleeping...\n";
|
2013-02-25 17:47:54 +00:00
|
|
|
|
sleep 30;
|
|
|
|
|
}
|
2009-03-23 01:13:37 +00:00
|
|
|
|
};
|
2012-03-07 17:48:10 +00:00
|
|
|
|
if ($@) { print STDERR "$@"; }
|
2008-11-11 10:27:36 +00:00
|
|
|
|
}
|