在不重新发明排队系统的情况下实现摘要电子邮件的最优雅方法是什么? [英] What's the most elegant way to implement a digest email without reinventing a queueing system?

查看:31
本文介绍了在不重新发明排队系统的情况下实现摘要电子邮件的最优雅方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的交易电子邮件系统设置 &默认情况下,人们会在事件发生时收到电子邮件:

class 注释after_create :email_original_posterdef email_original_posterUserMailer.delay.notify_author_of_comment self结尾结尾

但是,我的大部分用户更喜欢每日或每周摘要,而不是即时收到电子邮件.

最简洁、最优雅的实现方式是什么?

我已经让 delayed_job 运行了,但这感觉不像是一个 delayed_job 工作,因为我正在排队需要处理而不是操作的数据需要执行.

...无需重新发明排队系统

我知道显而易见的解决方案是 queued_emails 表,当然我可以这样做.我问这个问题的原因是这样做是为了重新发明一个排队系统.不仅有很多排队系统,而且正如 Percona 的这篇措辞恰当的帖子所指出的,最好不要自己推出:

http://www.engineyard.com/blog/2011/5-subtle-ways-youre-using-mysql-as-a-queue-and-why-itll-bite-you/p>

您是否实现了摘要电子邮件,您是否使用 delayed_job &你学到了什么?

解决方案

摘要看起来更适合作为 cron 作业来完成.您仍然必须控制您发送了谁",以处理崩溃和错误,但我们的想法是,例如,每天运行一个自定义 rake 任务来制作您的邮件消息,其中包括所有信息摘要格式,它们发送或排队等待发送.

I have my transactional email system setup & by default people get emails as events happen:

class Comment

  after_create :email_original_poster

  def email_original_poster
    UserMailer.delay.notify_author_of_comment self
  end

end

However instead of getting the email as-it-happens, a chunk of my users would prefer a daily or weekly digest.

What's the cleanest most elegant way to implement this?

I've already got delayed_job running but this doesn't really feel like a delayed_job job since I'm queueing data that needs to be acted on rather than actions that need to be executed.

...without reinventing a queueing system

I know that the obvious solution is table of queued_emails and of course I could do that. The reason I'm asking the question is that to do so is reinventing a queueing system. Not only are there lots of queuing systems out there but as this well worded post from Percona points out, it's a good idea not to roll your own:

http://www.engineyard.com/blog/2011/5-subtle-ways-youre-using-mysql-as-a-queue-and-why-itll-bite-you/

Have you implemented a digest email, did you use delayed_job & what did you learn?

解决方案

A digest looks like more appropriate to be done as a cron job like. You would still have to control to "who you have sent", to deal with crashes and errors, but the idea is to run, for example, on a daily basis, a custom rake task that craft your mail message including all info in a digest format and them send or queue for sending.

这篇关于在不重新发明排队系统的情况下实现摘要电子邮件的最优雅方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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