Skip to content
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

Merged
merged 4 commits into from
Sep 26, 2023

Conversation

adityathebe
Copy link
Member

  • setup new pg notifications when tables are updated

@github-actions
Copy link

github-actions bot commented Sep 22, 2023

E2E -

0 tests   0 ✔️  0s ⏱️
0 suites  0 💤
0 files    0

Results for commit 6fe467a.

♻️ This comment has been updated with latest results.

@adityathebe adityathebe marked this pull request as draft September 22, 2023 13:47
@adityathebe adityathebe force-pushed the feat/notification-status branch 2 times, most recently from af2830a to 13418ed Compare September 22, 2023 14:10
@@ -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 $$
Copy link
Member Author

@adityathebe adityathebe Sep 26, 2023

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.

Comment on lines -243 to -262
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 ();

Copy link
Member Author

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);
Copy link
Member Author

@adityathebe adityathebe Sep 26, 2023

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.

Copy link
Member Author

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.

@moshloop moshloop merged commit f0a43c4 into main Sep 26, 2023
6 checks passed
@moshloop moshloop deleted the feat/notification-status branch September 26, 2023 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants