使用delayed_jobs 每 5 分钟发送 50 封邮件
我尝试在Rails 中创建一个基于delayed_jobs 的邮件列表功能。现在,我通过迭代用户表来发送邮件,并将邮件.deliver
发送到每个邮件地址。
我怎样才能将它集成到delayed_jobs中,以便它每5分钟发送50封邮件并记住哪些地址已经完成?我是否需要创建一个单独的表来存储所有已发送的邮件并在每次发送另外 50 封邮件时回来查看?
提前致谢。
I try to create a mailing list feature in Rails which is based on delayed_jobs. For now I send mails by iterating over a users table and .deliver
a mail to every mail address.
how can i integrate it into delayed_jobs, so it sends 50 mails every 5 minutes and remembers which adresses are already done? do i need to make a seperate table where i store all sent mails and check back everytime i send another 50 mails?
thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能希望有已发送电子邮件的表条目。这样,如果流程出现故障或因某种原因而失败,它可以作为审计跟踪。
建议您考虑使用弹性云数据库(如 MongoLab、MongoHQ 或 SimpleDB)来执行此操作。 (基于 Mongo 的服务可以轻松扩展新电子邮件条目的架构。)
如果您这样做,那么像 SimpleWorker 这样的云工作队列可以轻松同时或批量发送大量电子邮件,以绕过任何速率限制。 (全面披露:我在 Iron.io/SimpleWorker 工作)
您正在采取一种很好的方法将多个电子邮件发送捆绑到单个工作任务中,以分摊工作人员设置成本。借助弹性云工作人员系统,您可以让主工作人员按计划完成任务,然后对许多从属工作人员任务进行排队,每个从属工作人员任务都有一组要发送的用户。
通过表条目,您可以返回浏览数据表并处理任何失败或未通过的电子邮件。
You will probably want to have table entries for sent emails. That way it serves as an audit trail if processes go down or somehow fail.
Suggest you look at doing this with an elastic cloud database like MongoLab, MongoHQ or SimpleDB. (Mongo-based services make it easy to extend the schema for new email entries.)
If you do that, then a cloud worker queue like SimpleWorker can make it easy to send out lots of emails concurrently or in batches to get around any rate limits. (full disclosure: I work at Iron.io/SimpleWorker)
You're taking a good approach to bundle multiple email sends into a single worker task to amortize the worker setup costs. With an elastic cloud worker system, you could have master workers come off schedule and then queue up a number of slave worker tasks, each with a set of users to send.
With table entries, you can then go back through the data tables and address any emails that failed or didn't go through.
我认为 50 封电子邮件并不是几秒钟内就能发送出去的。使用
foreverb
每 5 分钟发送一次电子邮件。50 emails is not really so much can be sent in seconds, I think. Use
foreverb
for sending emails every 5 minutes.让延迟的工作完成所有工作:
这应该可行,但未经测试。
Let delayed job do all the work:
This should work but untested.