-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add error column to notifications table #287
Conversation
adityathebe
commented
Sep 22, 2023
- setup new pg notifications when tables are updated
af2830a
to
13418ed
Compare
* setup new pg notifications when tables are updated
9a7b323
to
6fe467a
Compare
@@ -218,48 +218,6 @@ WHERE | |||
GROUP BY | |||
name; | |||
|
|||
-- Insert team updates in event_queue | |||
CREATE | |||
OR REPLACE FUNCTION insert_team_in_event_queue () RETURNS TRIGGER AS $$ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this event because the event consumer in IC were simply clearing the teams
& responder
cache. https://github.com/flanksource/incident-commander/blob/1265484533b60bfb1196c017e9769dfc9151a617/events/teams.go#L34-L70
Instead now we have PG Notify on the teams table which is better suited for our needs.
CREATE OR REPLACE FUNCTION notifications_trigger_function() | ||
RETURNS TRIGGER AS $$ | ||
BEGIN | ||
IF TG_OP = 'DELETE' THEN | ||
INSERT INTO event_queue(name, properties) VALUES ('notification.delete', jsonb_build_object('id', OLD.id)) | ||
ON CONFLICT (name, properties) DO UPDATE SET created_at = NOW(), last_attempt = NULL, attempts = 0; | ||
ELSE | ||
INSERT INTO event_queue(name, properties) VALUES ('notification.update', jsonb_build_object('id', NEW.id)) | ||
ON CONFLICT (name, properties) DO UPDATE SET created_at = NOW(), last_attempt = NULL, attempts = 0; | ||
END IF; | ||
|
||
RETURN NULL; | ||
END | ||
$$ LANGUAGE plpgsql; | ||
|
||
CREATE OR REPLACE TRIGGER notification_update_enqueue | ||
AFTER INSERT OR UPDATE OR DELETE ON notifications | ||
FOR EACH ROW | ||
EXECUTE PROCEDURE notifications_trigger_function (); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this event for the same reason. The consumer was simply clearing notification cache.
It's now moved to PG Notify listener.
CREATE OR REPLACE FUNCTION handle_team_updates() | ||
RETURNS TRIGGER AS $$ | ||
BEGIN | ||
IF TG_OP = 'DELETE' THEN | ||
PERFORM pg_notify('table_activity', TG_TABLE_NAME || ' ' || OLD.id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created a new NOTIFY channel table_activity
which should be used to publish any updates on a table (Insert, update, delete) instead of having multiple notify channels like teams_updated
or notifications_updated
.
This way we can use the notify router and have one listener on the NOTIFY channel and then distribute to multiple consumers based on the table name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The payload should be in the format <route> <an optional payload>
. The route is used by the pg notify router and the remaining payload is sent to the consumers.