[英]What is the proper way to handle reminder emails?
My rails app will send a reminder email if a user has not composed any new posts in three days. 如果用户三天内未撰写任何新帖子,我的Rails应用程序将发送一封提醒电子邮件。 This is defined as a rake task that is scheduled.
这被定义为计划的耙任务。
The task is scheduled every day. 该任务是每天安排的。 Of course, the task should only fire once for every user.
当然,该任务仅应为每个用户触发一次。 A user should get it on the third day and then never again.
用户应在第三天获得,然后再也不会。 On the tenth day, I might fire a totally different email.
在第十天,我可能会发送完全不同的电子邮件。
I know that adding a column called received_reminder
to the user table is an option. 我知道,添加一个名为列
received_reminder
用户表是一个选项。 When you fire the task, you would change received_reminder
to true
and clean it out again when a user creates a new post. 当你火了任务,你会改变
received_reminder
到true
和当用户创建一个新的岗位重新清理出来。 Multiple reminders would mean a new column for every reminder. 多个提醒将意味着每个提醒都有一个新列。 Eg
received_reminder_5days
etc. – this seems not to DRY in opinion and I suspect that there might be a better way generally. 例如,
received_reminder_5days
等-DRY认为这似乎不可行,我怀疑通常可能会有更好的方法。
What is the best practice in terms of reminder emails? 关于提醒电子邮件的最佳做法是什么?
You even do not need an extra field. 您甚至不需要一个额外的字段。 You can set up an array
reminder_days = [3,5,10,15]
(for example) and then once a day check whether the age d
(in days) of the users last post (which can be obtained from the database) is a member of reminder_days
. 您可以设置一个数组
reminder_days = [3,5,10,15]
(例如),然后每天检查一次用户最近一次发布的年龄d
(以天为单位)(可以从数据库中获取) reminder_days
的成员。 If it is, you send a reminder. 如果是,则发送提醒。 This reminder is the
n+1
th reminder if n
is the index of d
in the array reminder_days
. 如果
n
是dicker_days数组中d
的索引,则此提醒为第n+1
次reminder_days
。
To be really safe even in the case that the process of daily sending out reminder emails is interrputed, you could store the numbers of reminders that have already been sent in a field reminder_count
. 要想真正安全的,即使在情况下,每天发出提醒邮件的过程interrputed,你可以存储已经在现场发送提醒的数量
reminder_count
。 This field is set to 0 whenever the user creates a new post, and it is increased whenever a reminder is sent. 每当用户创建新帖子时,此字段都设置为0;每当发送提醒时,该字段就会增加。 With this field, you can check at any time whether a reminder still needs to be sent today or not (check whether
n==reminder_count
). 使用此字段,您可以随时检查是否仍需要今天发送
n==reminder_count
(检查是否n==reminder_count
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.