From bbee81efae394bb0b828b05cae3ebe8361b0a6d2 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 8 Jul 2015 12:05:32 +0200 Subject: [PATCH] Use triggers for all notifications on Builds table changes --- src/lib/Hydra/Helper/Nix.pm | 3 --- src/script/hydra-evaluator | 2 -- src/sql/hydra.sql | 21 ++++++++++++--------- src/sql/upgrade-35.sql | 21 ++++++++++++--------- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/lib/Hydra/Helper/Nix.pm b/src/lib/Hydra/Helper/Nix.pm index 0266d314..8c955e52 100644 --- a/src/lib/Hydra/Helper/Nix.pm +++ b/src/lib/Hydra/Helper/Nix.pm @@ -433,7 +433,6 @@ sub cancelBuilds($$) { , starttime => $time , stoptime => $time }); - $db->storage->dbh->do("notify builds_cancelled"); return $n; }); } @@ -470,8 +469,6 @@ sub restartBuilds($$) { # FIXME: Add this to the API. # FIXME: clear the dependencies? $db->resultset('FailedPaths')->search({ path => [ @paths ]})->delete; - - $db->storage->dbh->do("notify builds_restarted"); }); return scalar(@buildIds); diff --git a/src/script/hydra-evaluator b/src/script/hydra-evaluator index d78eeaa8..072a755e 100755 --- a/src/script/hydra-evaluator +++ b/src/script/hydra-evaluator @@ -234,8 +234,6 @@ sub checkJobsetWrapped { print STDERR " created new eval ", $ev->id, "\n"; $ev->builds->update({iscurrent => 1}); - - $db->storage->dbh->do("notify builds_added"); } 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 1a6f6938..1ade4e38 100644 --- a/src/sql/hydra.sql +++ b/src/sql/hydra.sql @@ -204,16 +204,19 @@ create table Builds ( #ifdef POSTGRESQL -create function notifyBuildDeleted() returns trigger as $$ - begin - execute 'notify builds_deleted'; - return null; - end; -$$ language plpgsql; +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 trigger BuildDeleted after delete on Builds - for each row - execute procedure notifyBuildDeleted(); +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(); + +create function notifyBuildRestarted() returns trigger as 'begin notify builds_restarted; return null; end;' language plpgsql; +create trigger BuildRestarted after update on Builds for each row + when (old.finished = 1 and new.finished = 0) execute procedure notifyBuildRestarted(); + +create function notifyBuildCancelled() returns trigger as 'begin notify builds_cancelled; return null; end;' language plpgsql; +create trigger BuildCancelled after update on Builds for each row + when (old.finished = 0 and new.finished = 1 and new.buildStatus = 4) execute procedure notifyBuildCancelled(); #endif diff --git a/src/sql/upgrade-35.sql b/src/sql/upgrade-35.sql index 9d05c770..268c4fea 100644 --- a/src/sql/upgrade-35.sql +++ b/src/sql/upgrade-35.sql @@ -1,10 +1,13 @@ -create function notifyBuildDeleted() returns trigger as $$ - begin - execute 'notify builds_deleted'; - return null; - end; -$$ language plpgsql; +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 trigger BuildDeleted after delete on Builds - for each row - execute procedure notifyBuildDeleted(); +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(); + +create function notifyBuildRestarted() returns trigger as 'begin notify builds_restarted; return null; end;' language plpgsql; +create trigger BuildRestarted after update on Builds for each row + when (old.finished = 1 and new.finished = 0) execute procedure notifyBuildRestarted(); + +create function notifyBuildCancelled() returns trigger as 'begin notify builds_cancelled; return null; end;' language plpgsql; +create trigger BuildCancelled after update on Builds for each row + when (old.finished = 0 and new.finished = 1 and new.buildStatus = 4) execute procedure notifyBuildCancelled();