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 , starttime => $time
, stoptime => $time , stoptime => $time
}); });
$db->storage->dbh->do("notify builds_cancelled");
return $n; return $n;
}); });
} }
@ -470,8 +469,6 @@ sub restartBuilds($$) {
# FIXME: Add this to the API. # FIXME: Add this to the API.
# FIXME: clear the dependencies? # FIXME: clear the dependencies?
$db->resultset('FailedPaths')->search({ path => [ @paths ]})->delete; $db->resultset('FailedPaths')->search({ path => [ @paths ]})->delete;
$db->storage->dbh->do("notify builds_restarted");
}); });
return scalar(@buildIds); return scalar(@buildIds);

View file

@ -234,8 +234,6 @@ sub checkJobsetWrapped {
print STDERR " created new eval ", $ev->id, "\n"; print STDERR " created new eval ", $ev->id, "\n";
$ev->builds->update({iscurrent => 1}); $ev->builds->update({iscurrent => 1});
$db->storage->dbh->do("notify builds_added");
} else { } else {
print STDERR " created cached eval ", $ev->id, "\n"; print STDERR " created cached eval ", $ev->id, "\n";
$prevEval->builds->update({iscurrent => 1}) if defined $prevEval; $prevEval->builds->update({iscurrent => 1}) if defined $prevEval;

View file

@ -204,16 +204,19 @@ create table Builds (
#ifdef POSTGRESQL #ifdef POSTGRESQL
create function notifyBuildDeleted() returns trigger as $$ create function notifyBuildsAdded() returns trigger as 'begin notify builds_added; return null; end;' language plpgsql;
begin create trigger BuildsAdded after insert on Builds execute procedure notifyBuildsAdded();
execute 'notify builds_deleted';
return null;
end;
$$ language plpgsql;
create trigger BuildDeleted after delete on Builds create function notifyBuildsDeleted() returns trigger as 'begin notify builds_deleted; return null; end;' language plpgsql;
for each row create trigger BuildsDeleted after delete on Builds execute procedure notifyBuildsDeleted();
execute procedure notifyBuildDeleted();
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 #endif

View file

@ -1,10 +1,13 @@
create function notifyBuildDeleted() returns trigger as $$ create function notifyBuildsAdded() returns trigger as 'begin notify builds_added; return null; end;' language plpgsql;
begin create trigger BuildsAdded after insert on Builds execute procedure notifyBuildsAdded();
execute 'notify builds_deleted';
return null;
end;
$$ language plpgsql;
create trigger BuildDeleted after delete on Builds create function notifyBuildsDeleted() returns trigger as 'begin notify builds_deleted; return null; end;' language plpgsql;
for each row create trigger BuildsDeleted after delete on Builds execute procedure notifyBuildsDeleted();
execute procedure notifyBuildDeleted();
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();