与Rackspace使用延迟作业时的ActionMailer“Net :: ReadTimeout”“emailsrvr.com”

时间:2014-03-27 21:38:16

标签: ruby-on-rails ruby actionmailer delayed-job

编辑:我使用的是Rails 3.2.17和Ruby 2.0.0p0

我在发送邮件时超时ActionMailer时遇到了一些问题;见ActionMailer Timing out

将默认Unicorn超时增加到2分钟(用于测试)它在大约45秒内完成。我认为处理此问题的最佳方法是使用Delayed Job,但是,当DJ运行deliver方法时,它也会超时。堆栈跟踪如下。

DJ是否适合这项工作?我是否需要增加DJ的超时时间(我以为我读过默认值为6小时)?任何建议都会有所帮助。

DJ致电:

NotificationsMailer.delay.access_granted(self).deliver

堆栈跟踪:

[Worker(host:myhost.local pid:37598)] Job Class#access_granted (id=20) FAILED (3 prior attempts) with Net::ReadTimeout: Net::ReadTimeout
   (0.3ms)  BEGIN
   (1.0ms)  UPDATE "delayed_jobs" SET "last_error" = 'Net::ReadTimeout
/Users/user/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/protocol.rb:158:in `rescue in rbuf_fill''
/Users/user/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/protocol.rb:152:in `rbuf_fill''
/Users/user/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/protocol.rb:134:in `readuntil''
/Users/user/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/protocol.rb:144:in `readline''
/Users/user/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/smtp.rb:931:in `recv_response''
/Users/user/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/smtp.rb:554:in `block in do_start''
/Users/user/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/smtp.rb:941:in `critical''
/Users/user/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/smtp.rb:554:in `do_start''
/Users/user/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/smtp.rb:519:in `start''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/mail-2.5.4/lib/mail/network/delivery_methods/smtp.rb:112:in `deliver!''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/mail-2.5.4/lib/mail/message.rb:2129:in `do_delivery''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/mail-2.5.4/lib/mail/message.rb:232:in `block in deliver''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/actionmailer-3.2.17/lib/action_mailer/base.rb:415:in `block in deliver_mail''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/activesupport-3.2.17/lib/active_support/notifications.rb:123:in `block in instrument''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/activesupport-3.2.17/lib/active_support/notifications/instrumenter.rb:20:in `instrument''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/activesupport-3.2.17/lib/active_support/notifications.rb:123:in `instrument''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/actionmailer-3.2.17/lib/action_mailer/base.rb:413:in `deliver_mail''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/mail-2.5.4/lib/mail/message.rb:232:in `deliver''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/performable_mailer.rb:6:in `perform''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/backend/base.rb:105:in `block in invoke_job''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:60:in `call''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:60:in `block in initialize''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:65:in `call''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:65:in `execute''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:38:in `run_callbacks''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/backend/base.rb:102:in `invoke_job''
(eval):3:in `block in invoke_job_with_newrelic_transaction_trace''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/newrelic_rpm-3.7.2.195/lib/new_relic/agent/instrumentation/controller_instrumentation.rb:339:in `perform_action_with_newrelic_trace''
(eval):2:in `invoke_job_with_newrelic_transaction_trace''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/worker.rb:206:in `block (2 levels) in run''
/Users/user/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/timeout.rb:65:in `timeout''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/worker.rb:206:in `block in run''
/Users/user/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/benchmark.rb:296:in `realtime''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/worker.rb:205:in `run''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/worker.rb:267:in `block in reserve_and_run_one_job''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:60:in `call''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:60:in `block in initialize''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:65:in `call''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:65:in `execute''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:38:in `run_callbacks''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/worker.rb:267:in `reserve_and_run_one_job''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/worker.rb:189:in `block in work_off''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/worker.rb:188:in `times''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/worker.rb:188:in `work_off''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/worker.rb:153:in `block (4 levels) in start''
/Users/user/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/benchmark.rb:296:in `realtime''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/worker.rb:152:in `block (3 levels) in start''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:60:in `call''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:60:in `block in initialize''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:65:in `call''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:65:in `execute''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:38:in `run_callbacks''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/worker.rb:151:in `block (2 levels) in start''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/worker.rb:150:in `loop''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/worker.rb:150:in `block in start''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/plugins/clear_locks.rb:7:in `call''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/plugins/clear_locks.rb:7:in `block (2 levels) in <class:ClearLocks>''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:78:in `call''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:78:in `block (2 levels) in add''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:60:in `call''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:60:in `block in initialize''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:78:in `call''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:78:in `block in add''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:65:in `call''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:65:in `execute''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/lifecycle.rb:38:in `run_callbacks''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/worker.rb:149:in `start''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/delayed_job-4.0.0/lib/delayed/tasks.rb:9:in `block (2 levels) in <top (required)>''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/rake-10.1.1/lib/rake/task.rb:236:in `call''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/rake-10.1.1/lib/rake/task.rb:236:in `block in execute''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/rake-10.1.1/lib/rake/task.rb:231:in `each''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/rake-10.1.1/lib/rake/task.rb:231:in `execute''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/rake-10.1.1/lib/rake/task.rb:175:in `block in invoke_with_call_chain''
/Users/user/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/rake-10.1.1/lib/rake/task.rb:168:in `invoke_with_call_chain''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/rake-10.1.1/lib/rake/task.rb:161:in `invoke''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/rake-10.1.1/lib/rake/application.rb:149:in `invoke_task''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/rake-10.1.1/lib/rake/application.rb:106:in `block (2 levels) in top_level''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/rake-10.1.1/lib/rake/application.rb:106:in `each''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/rake-10.1.1/lib/rake/application.rb:106:in `block in top_level''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/rake-10.1.1/lib/rake/application.rb:115:in `run_with_threads''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/rake-10.1.1/lib/rake/application.rb:100:in `top_level''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/rake-10.1.1/lib/rake/application.rb:78:in `block in run''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/rake-10.1.1/lib/rake/application.rb:165:in `standard_exception_handling''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/rake-10.1.1/lib/rake/application.rb:75:in `run''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/gems/rake-10.1.1/bin/rake:33:in `<top (required)>''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/bin/rake:23:in `load''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/bin/rake:23:in `<main>''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/bin/ruby_noexec_wrapper:14:in `eval''
/Users/user/.rvm/gems/ruby-2.0.0-p0@mysite/bin/ruby_noexec_wrapper:14:in `<main>''', "attempts" = 4, "run_at" = '2014-03-27 21:35:41.779268', "locked_at" = NULL, "locked_by" = NULL, "updated_at" = '2014-03-27 21:31:20.783344' WHERE "delayed_jobs"."id" = 20

1 个答案:

答案 0 :(得分:8)

在尝试了几十种不同的配置之后,这是最终有效的配置:

config.action_mailer.smtp_settings = {
  address:              "secure.emailsrvr.com",
  port:                 465,
  domain:               "myapp.net",
  authentication:       :login,
  tls:                  true,
  user_name:            "no-reply@myapp.net",
  password:             "PASSWORD"
}

此外,在我的Mailer课程中,我必须确保将默认from设置为与上面user_name相同的地址。

修改 需要说明的是,实现上述后我不再需要使用DJ