From 976d88d6758b8420980bc83aafbb4ab5af1e4579 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 12 Aug 2019 15:26:35 +0200 Subject: [PATCH] Send notifications when evaluations start/finish/fail * 'eval_started' has the format '\t\t'. * 'eval_failed' has the format ''. (The cause of the error can be found in the database.) * 'eval_added' has the format ':'. --- src/script/hydra-eval-jobset | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/script/hydra-eval-jobset b/src/script/hydra-eval-jobset index 9d375c1b..5b31c735 100755 --- a/src/script/hydra-eval-jobset +++ b/src/script/hydra-eval-jobset @@ -568,7 +568,7 @@ sub permute { sub checkJobsetWrapped { - my ($jobset) = @_; + my ($jobset, $tmpId) = @_; my $project = $jobset->project; my $jobsetsJobset = length($project->declfile) && $jobset->name eq ".jobsets"; my $inputInfo = {}; @@ -607,6 +607,7 @@ sub checkJobsetWrapped { print STDERR $fetchError; txn_do($db, sub { $jobset->update({ lastcheckedtime => time, fetcherrormsg => $fetchError }) if !$dryRun; + $db->storage->dbh->do("notify eval_failed, ?", undef, join('\t', $tmpId)); }); return; } @@ -622,6 +623,7 @@ sub checkJobsetWrapped { Net::Statsd::increment("hydra.evaluator.unchanged_checkouts"); txn_do($db, sub { $jobset->update({ lastcheckedtime => time, fetcherrormsg => undef }); + $db->storage->dbh->do("notify eval_cached, ?", undef, join('\t', $tmpId)); }); return; } @@ -690,6 +692,9 @@ sub checkJobsetWrapped { , nrbuilds => $jobsetChanged ? scalar(keys %buildMap) : undef }); + $db->storage->dbh->do("notify eval_added, ?", undef, + join('\t', $tmpId, $ev->id)); + if ($jobsetChanged) { # Create JobsetEvalMembers mappings. while (my ($id, $x) = each %buildMap) { @@ -767,10 +772,6 @@ sub checkJobsetWrapped { Net::Statsd::increment("hydra.evaluator.evals"); Net::Statsd::increment("hydra.evaluator.cached_evals") unless $jobsetChanged; - #while (my ($id, $x) = each %buildMap) { - # system("hydra-notify build-queued $id") if $x->{new}; - #} - # Store the error messages for jobs that failed to evaluate. my $msg = ""; foreach my $job (values %{$jobs}) { @@ -788,8 +789,15 @@ sub checkJobset { my $startTime = clock_gettime(CLOCK_MONOTONIC); + # Add an ID to eval_* notifications so receivers can correlate + # them. + my $tmpId = "${startTime}.$$"; + + $db->storage->dbh->do("notify eval_started, ?", undef, + join('\t', $tmpId, $jobset->get_column('project'), $jobset->name)); + eval { - checkJobsetWrapped($jobset); + checkJobsetWrapped($jobset, $tmpId); }; my $checkError = $@; @@ -802,6 +810,7 @@ sub checkJobset { txn_do($db, sub { $jobset->update({lastcheckedtime => time}); setJobsetError($jobset, $checkError); + $db->storage->dbh->do("notify eval_failed, ?", undef, join('\t', $tmpId)); }) if !$dryRun; $failed = 1; }