简体   繁体   English

构建用于提醒电子邮件的系统

[英]Architecting a system for reminder emails

I'm building a reservation system in Rails 4.2 where I need to send a set of emails to users at predefined intervals (for example that they have an upcoming reservation, feedback after it's done, a link to change/cancel an existing reservation, etc.). 我正在Rails 4.2中构建预订系统,我需要以预定义的时间间隔向用户发送一组电子邮件(例如,他们有即将到来的预订,完成后的反馈,更改/取消现有预订的链接等等)。 I've looked around and found this and this , but I'm trying to decide between the approaches. 我环顾四周,找到了这个这个 ,但我试图在这些方法之间做出决定。

I see two main ways of building this system out. 我看到了构建这个系统的两种主要方式。

  1. Using a queue system like delayed_job . 使用像delayed_job这样的队列系统。 Whenever someone makes a reservation, we queue up all the emails for the correct time when they should be sent. 每当有人进行预订时,我们会将所有电子邮件排队等候正确的时间。

    Pro: One queue for all emails. 专业版:所有电子邮件的一个队列。 Automatic retry logic. 自动重试逻辑。

    Con: Thousands of emails will eventually get queued in the system. 骗局:成千上万的电子邮件最终会在系统中排队。 Need to dequeue whenever someone cancels a reservation (dependent: destroy emails related to it might be pretty easy). 每当有人取消预订时需要出队(依赖:销毁与之相关的电子邮件可能非常简单)。 Somewhat more complex logic around what time we need the emails to go out. 关于我们需要电子邮件出去的时间有点复杂的逻辑。

  2. cron + rake task that runs at some predefined interval (hourly? every fifteen minutes?) and checks for the emails that need to go out. cron + rake任务以某个预定义的间隔运行(每小时?每十五分钟?)并检查需要外出的电子邮件。 It runs a query like "Find all reservations that are three days from now", and then sends out all emails. 它运行一个查询,如“查找从现在开始三天的所有预订”,然后发送所有电子邮件。

    Pro: Put everything into application logic, reduce the amount of state we need to keep track of. Pro:将所有内容都放入应用程序逻辑中,减少我们需要跟踪的状态量。

    Con: Need to keep track of which emails have been sent, which is conceptually similar to whatever jobs table we already have created above. Con:需要跟踪已发送的电子邮件,这在概念上类似于我们上面创建的任何作业表。

第二种方法更好(如果在heroku上使用heroku调度程序),队列更多用于“尽快运行”而不是“在此特定日期时间运行”

The one good advantage of 1) using delayed_job (or Sidekiq) is that you could update the schedule of a job (or a recurring job) from the site dynamically. 1)使用delayed_job(或Sidekiq)的一个好处是,您可以动态地从站点更新作业(或定期作业)的计划。

You can provide a page in your site to update recurring jobs. 您可以在站点中提供页面以更新定期作业。 Now, delayed_job doesn't really allow recurring jobs by default. 现在,delayed_job默认情况下不会真正允许重复作业。 There are add-on gems that could be of interest though delayed_job_recurring or sidekiq-scheduler . 虽然有delayed_job_recurringsidekiq-scheduler,但有一些附加的宝石可能会引起关注。 If compute power is not a problem, I would always prefer an actual job processor rather than cron because it is just more manageable for me. 如果计算能力不是问题,我总是更喜欢实际的工作处理器而不是cron,因为它对我来说更容易管理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM