【发布时间】:2014-06-04 20:29:58
【问题描述】:
我在 nginx 上运行 rails。然后我就有了一次向所有注册用户发送电子邮件的功能。
我确实运行了这个,但它出现了超时错误。我怎样才能解决这个问题?如何修改我的配置?
controller(有超过 10000 个用户,所以这意味着这个邮件程序重复了 10000 次)
users.each do |user|
if user.nomail.blank?
CallMailer.call_email_to(user.email, subject, body).deliver
sent_to_count = sent_to_count + 1
end
end
然后它得到这个超时错误。
The connection has timed outThe server www.foofooexample.com is taking too long to respond.
这是我的 nginx 的配置文件
etc/nginx/conf.d/foo.conf
server {
listen 80;
server_name foofooexample.com;
root /var/www/html/foo/public;
client_max_body_size 5M;
keepalive_timeout 1200;
proxy_connect_timeout 1200;
proxy_read_timeout 1200;
proxy_send_timeout 1200;
.
.
.
【问题讨论】:
-
这样的任务不应该在(等待的)网络请求中完成。您应该在后台执行此操作,有很多 gem 可以执行此操作,例如 sidekiq。
-
@Tamer 感谢您的评论! sidekiq 会做我在控制器中所做的事情吗?它正在加载所有用户并向所有用户发送消息。
标签: ruby-on-rails ruby-on-rails-3 nginx