Support push notification of repository changes
External machines can now notify Hydra that it should check a repository by sending a GET or PUSH request to /api/push, providing a list of jobsets to be checked and/or a list of repository URLs. In the latter case, all jobsets that have any of the specified repositories as an input will be checked. For instance, you can configure GitHub or BitBucket to send a request to the URL http://hydra.example.org/api/push?repos=git://github.com/NixOS/nixpkgs.git to trigger evaluation of all jobsets that have git://github.com/NixOS/nixpkgs.git as an input, or to the URL http://hydra.example.org/api/push?jobsets=patchelf:trunk,nixpkgs:trunk to trigger evaluation of just the specified jobsets.
This commit is contained in:
@ -21,7 +21,7 @@ my $db = Hydra::Model::DB->new();
|
||||
my $config = getHydraConfig();
|
||||
|
||||
# Don't check a jobset more than once every five minutes.
|
||||
my $minCheckInterval = 1;
|
||||
my $minCheckInterval = 5 * 60;
|
||||
|
||||
|
||||
|
||||
@ -232,6 +232,8 @@ sub checkJobset {
|
||||
? " (last checked " . (time() - $jobset->lastcheckedtime) . "s ago)\n"
|
||||
: " (never checked)\n";
|
||||
|
||||
my $triggerTime = $jobset->triggertime;
|
||||
|
||||
eval {
|
||||
checkJobsetWrapped($jobset);
|
||||
};
|
||||
@ -244,15 +246,35 @@ sub checkJobset {
|
||||
setJobsetError($jobset, $msg);
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Check the jobset that hasn't been checked for the longest time.
|
||||
sub checkSomeJobset {
|
||||
# If any jobset has been triggered by a push, check it.
|
||||
my ($jobset) = $db->resultset('Jobsets')->search(
|
||||
{ 'project.enabled' => 1, 'me.enabled' => 1
|
||||
{ 'project.enabled' => 1, 'me.enabled' => 1, 'triggertime' => { '!=', undef },
|
||||
, -or => [ 'lastcheckedtime' => undef, 'lastcheckedtime' => { '<', time() - $minCheckInterval } ] },
|
||||
{ join => 'project', order_by => [ 'lastcheckedtime nulls first' ], rows => 1 });
|
||||
{ join => 'project', order_by => [ 'triggertime' ], rows => 1 });
|
||||
|
||||
# Otherwise, check the jobset that hasn't been checked for the
|
||||
# longest time (but don't check more often than the minimal check
|
||||
# interval).
|
||||
($jobset) = $db->resultset('Jobsets')->search(
|
||||
{ 'project.enabled' => 1, 'me.enabled' => 1,
|
||||
, -or => [ 'lastcheckedtime' => undef, 'lastcheckedtime' => { '<', time() - $minCheckInterval } ] },
|
||||
{ join => 'project', order_by => [ 'lastcheckedtime nulls first' ], rows => 1 })
|
||||
unless defined $jobset;
|
||||
|
||||
return 0 unless defined $jobset;
|
||||
|
||||
|
Reference in New Issue
Block a user