Sending dynamic email reminders in Ruby on Rails?

帅比萌擦擦* 提交于 2019-12-11 03:22:33

问题


I'm relatively new to actionmailer however I have set up forgot password emails and have them running as delayed jobs already. I would like to set up dynamic email reminders where users can select options like "Remind me ___ minutes/hours/days" before an event start and have it send an email reminder. I don't want to leave it completely open-ended and will have a dropdown with the following options:

  • Remind me at the time of event
  • Remind me 5/15/30 minutes before the event
  • Remind me 1 hour before the event
  • Remind me 1 day before the event

What is the best/most efficient way to accomplish this? Can the delayed jobs run_at function accomplish this or should I write a delivery method for each of the dropdown options calling something that says to deliver the mail at

event_start - 60.minutes 

or something like that? My app is using Rails 3.0.11 and this is different from a daily cron task because these could run at any time. Also, will it cause any problems with the delayed jobs if a user is able to edit the event dates changing the start and end dates?


回答1:


Probably best to store this info in a database, and set up a single delayed job for each time period before each event.

ie. For event A, only 6 delayed jobs, one 1 day before event, another 1 hour before, another 30 mins before, ...

Then the delayed job can look in the database for which users need the reminder email.

If instead you set up the delayed job when the user selected it, then what if they change their mind? It would make it harder to delete/change when the delayed job runs for a particular user.

Also if many users want emails at once, it might cause traffic problems with multiple jobs trying to run at the same time. Instead, a single job emailing the list of users one at a time will cause less of a problem.



来源:https://stackoverflow.com/questions/12022650/sending-dynamic-email-reminders-in-ruby-on-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!