简体   繁体   English

使用 Rails 通过 Sendgrid 发送大量邮件

[英]Sending a large amount of mail via Sendgrid with Rails

As mentioned in the title, I'm trying to send daily newsletters via sendgrid with Rails, and I'm generating a large Array of Json objects (around 20 000).正如标题中提到的,我正在尝试使用 Rails 通过 sendgrid 发送每日新闻通讯,并且我正在生成大量 Json 对象(大约 20 000 个)。 What is the best practice of temporary storing this array which is needed only to build the email format, and no more after the emails list are sent.临时存储此数组的最佳实践是什么,该数组仅用于构建电子邮件格式,并且在发送电子邮件列表后不再需要。

Any help would be very much appreciated.任何帮助将不胜感激。

The least harmful way of dealing with any kind of asynchronous task, like sending one or thousands of emails, is using a queue.处理任何类型的异步任务(例如发送一封或数千封电子邮件)危害最小的方法是使用队列。

If you are using the most recent versions of Rails, you should check it out ActiveJobs: https://guides.rubyonrails.org/active_job_basics.html如果您使用的是最新版本的 Rails,您应该查看 ActiveJobs: https ://guides.rubyonrails.org/active_job_basics.html

If not, there are various gems that covers the same situation.如果不是,则有各种 gem 可以涵盖相同的情况。 The one that people uses the most is Sidekiq: https://github.com/mperham/sidekiq人们使用最多的是 Sidekiq: https : //github.com/mperham/sidekiq

Basically, you put a task on a queue that will be consumed outside of the scope of your application.基本上,您将一个任务放在一个队列中,该队列将在您的应用程序范围之外使用。 When there is no more task to perform, it will just wait for more on the background.当没有更多任务要执行时,它只会在后台等待更多任务。

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

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