Use triggers for all notifications on Builds table changes

This commit is contained in:
Eelco Dolstra 2015-07-08 12:05:32 +02:00
parent 89fb723ace
commit bbee81efae
4 changed files with 24 additions and 23 deletions

View file

@ -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);

View file

@ -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;

View file

@ -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

View file

@ -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();