简体   繁体   English

使用动作邮件发送大量电子邮件的基于性能的方法是什么?

[英]what is a performance oriented method to send mass emails using action mailer?

Given a user model and a post model, what is the best way to send mass email to all users when a new post is made without it clogging the application process? 给定用户模型和帖子模型,在撰写新帖子而又不阻塞应用程序的情况下,向所有用户发送大量电子邮件的最佳方法是什么?

Putting it in the controller halts the application. 将其放在控制器中会暂停应用程序。 I was also looking into Active Job but it seems that it is not event driven. 我也正在研究Active Job,但似乎它不是事件驱动的。

You'll want to use a queue like ActiveJob anytime your Rails app needs to do something that is: 每当您的Rails应用程序需要执行以下操作时,您都想使用ActiveJob之类的队列:

  • long-running 长期运行
  • relies on another application that might fail or be unavailable 依赖于可能失败或不可用的另一个应用程序

Queueing the email job lets your application respond quickly (eg "message being sent") and ensures that it won't be lost if the email server is down. 对电子邮件作业进行排队可以使您的应用程序快速响应(例如“正在发送的消息”),并确保在电子邮件服务器关闭时不会丢失它。 Use a callback to do whatever you need after the message is queued or sent (eg email "Message Delivered"). 在消息排队或发送后(例如,电子邮件“消息已发送”),使用回调函数执行所需的任何操作。

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

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