diff --git a/src/hydra-queue-runner/queue-monitor.cc b/src/hydra-queue-runner/queue-monitor.cc index 09d07342..f94007d2 100644 --- a/src/hydra-queue-runner/queue-monitor.cc +++ b/src/hydra-queue-runner/queue-monitor.cc @@ -48,8 +48,10 @@ void State::queueMonitorLoop() } else conn->get_notifs(); - if (buildsAdded.get()) + if (auto lowestId = buildsAdded.get()) { + lastBuildId = std::stoi(*lowestId) - 1; printMsg(lvlTalkative, "got notification: new builds added to the queue"); + } if (buildsRestarted.get()) { printMsg(lvlTalkative, "got notification: builds restarted"); lastBuildId = 0; // check all builds @@ -75,7 +77,7 @@ struct PreviousFailure : public std::exception { bool State::getQueuedBuilds(Connection & conn, ref destStore, unsigned int & lastBuildId) { - printMsg(lvlInfo, format("checking the queue for builds > %1%...") % lastBuildId); + printInfo("checking the queue for builds > %d...", lastBuildId); /* Grab the queued builds from the database, but don't process them yet (since we don't want a long-running transaction). */ diff --git a/src/libhydra/db.hh b/src/libhydra/db.hh index 9b5b7348..5bb5aac5 100644 --- a/src/libhydra/db.hh +++ b/src/libhydra/db.hh @@ -21,18 +21,23 @@ struct Connection : pqxx::connection }; -struct receiver : public pqxx::notification_receiver +class receiver : public pqxx::notification_receiver { - bool status = false; + std::experimental::optional status; + +public: + receiver(pqxx::connection_base & c, const std::string & channel) : pqxx::notification_receiver(c, channel) { } + void operator() (const std::string & payload, int pid) override { - status = true; + status = payload; }; - bool get() { - bool b = status; - status = false; - return b; + + std::experimental::optional get() { + auto s = status; + status = std::experimental::nullopt; + return s; } }; diff --git a/src/script/hydra-eval-jobset b/src/script/hydra-eval-jobset index 7b280945..0641c9d5 100755 --- a/src/script/hydra-eval-jobset +++ b/src/script/hydra-eval-jobset @@ -25,6 +25,8 @@ STDERR->autoflush(1); binmode STDERR, ":encoding(utf8)"; my $db = Hydra::Model::DB->new(); +my $notifyAdded = $db->storage->dbh->prepare("notify builds_added, ?"); + my $config = getHydraConfig(); my $plugins = [Hydra::Plugin->instantiate(db => $db, config => $config)]; @@ -720,6 +722,14 @@ sub checkJobsetWrapped { print STDERR " created new eval ", $ev->id, "\n"; $ev->builds->update({iscurrent => 1}); + + # Wake up hydra-queue-runner. + my $lowestId; + while (my ($id, $x) = each %buildMap) { + $lowestId = $id if $x->{new} && (!defined $lowestId || $id < $lowestId); + } + $notifyAdded->execute($lowestId) if defined $lowestId; + } else { print STDERR " created cached eval ", $ev->id, "\n"; $prevEval->builds->update({iscurrent => 1}) if defined $prevEval; diff --git a/src/sql/hydra.sql b/src/sql/hydra.sql index 7fd37f00..197a7dfb 100644 --- a/src/sql/hydra.sql +++ b/src/sql/hydra.sql @@ -233,9 +233,6 @@ create table Builds ( #ifdef POSTGRESQL -create function notifyBuildsAdded() returns trigger as 'begin notify builds_added; return null; end;' language plpgsql; -create trigger BuildsAdded after insert on Builds execute procedure notifyBuildsAdded(); - create function notifyBuildsDeleted() returns trigger as 'begin notify builds_deleted; return null; end;' language plpgsql; create trigger BuildsDeleted after delete on Builds execute procedure notifyBuildsDeleted(); diff --git a/src/sql/upgrade-54.sql b/src/sql/upgrade-54.sql new file mode 100644 index 00000000..7c8b09bf --- /dev/null +++ b/src/sql/upgrade-54.sql @@ -0,0 +1,2 @@ +drop trigger BuildsAdded on Builds; +drop function notifyBuildsAdded();