Hacker News new | past | comments | ask | show | jobs | submit login

How 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...



Thanks, 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!


You 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.


Thank you! Thank you so much :)


You'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 *




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: