3 ms·
This could slightly out of context. I'm working on a module that send notifications to a user when an alert is generated. I have PostGreSQL as the database and
by 120bits 7y ago
This could slightly out of context.
I'm working on a module that send notifications to a user when an alert is generated. I have PostGreSQL as the database and NodeJS is the handler and for connection pooling. Are there any good pub/sub tools that I can use.
Thanks in advance.
- porsager 7y agoHow about simply having an after insert trigger on an alerts table that calls notify, and then you listen for that in node? It's a simple setup with less moving parts and could probably get you a long way...
- 120bits 7y agoThanks, this will probably work for me. However, if the inserts are higher, I don't want to get notified that frequently. How would I add a periodic alerts to this? Thank you!
- porsager 7y agoYou could use a column/table to track notifications. Eg. have an alert_sent_at column on the alerts table. Then when the node service receives the notify on an insert you can defer based on any logic you need, and send notifications when needed by a query that fetches alerts with alert_sent_at = null.
- 120bits 7y agoThank you! Thank you so much :)
- porsager 7y agoYou're welcome. To ensure you're not sending alerts twice either select and update in a transaction or use a CTE like: with alert as ( select alert_id from alerts where alert_sent_at is null ) update alerts set alert_sent_at = now() from alert returning *