Email Digest for Rail Application
I am working on a rails application where people can follow each other and post comments. Currently I use delayed_jobs for people to get notifications when someone follows them or post a comme开发者_如何学编程nt. My question is how can I collect all the notifications for one user and create an email digest for notifications and send the email at the end of the day. Putting it in another way, can we collate the delayed_jobs?
Delayed_job won't do this for you, but it's straightforward enough to do yourself.
The simplest thing to do would be to write a rake task that you run once a day, and have the task find all the activity for that user that has occurred in the past day, and then send them an email about that activity.
Right now you are sending an email on a set of actions (following event or comment event).
Instead, if your user is digest-enabled, insert a record into a pending-email-digest table, and then daily process the email digests via a cron job.
精彩评论