在Ruby on Rails中发送动态电子邮件提醒? [英] Sending dynamic email reminders in Ruby on Rails?

查看:181
本文介绍了在Ruby on Rails中发送动态电子邮件提醒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对actionmailer比较新,但是我已经设置了忘记的密码电子邮件,并将其作为已延迟的工作运行。我想设置动态电子邮件提醒,用户可以在活动开始之前选择提醒我 _ __ 分钟/小时/天,并发送电子邮件提醒。我不想让它完全开放,并且将有一个下拉列表与以下选项:




  • 提醒我在事件

  • 在活动前5/15/30分钟提醒我

  • 在活动前1小时提醒我

  • 提醒事件发生前一天



什么是最好的/最有效的方式来完成这个?延迟作业run_at函数可以完成此操作,还是应该为每个下拉选项写一个传递方法,这些选项调用在

  event_start  -  60.minutes 

或类似的东西?我的应用程序正在使用Rails 3.0.11,这与每日cron任务不同,因为这些任务可以随时运行。此外,如果用户能够编辑更改开始和结束日期的事件日期,是否会导致任何延迟作业的问题?

解决方案

可能最好将此信息存储在数据库中,并在每个事件之前的每个时间段设置单个延迟作业。



ie。对于事件A,只有6个延迟工作,事件前1天,另外1小时前,另外30分钟之前,...



然后延迟的工作可以查看用户需要提醒电子邮件的数据库。



如果相反,您在用户选择时设置延迟作业,那么如果他们改变主意呢?当特定用户运行延迟的作业时,会更难删除/更改。



如果许多用户一次需要电子邮件,那么可能会导致多个工作试图同时运行。相反,一次发送一个用户列表的单个作业将会导致更少的问题。


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?

解决方案

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.

这篇关于在Ruby on Rails中发送动态电子邮件提醒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆