我正在使用whenever
gem 执行每日发送电子邮件的任务。我在 RAKEFILE 名称咖啡中创建了一个 rake 任务。这是我的任务代码:
task :coffee => :environment do
ReservationBooksNotify.notify.deliver
puts "hihi"
end
当我在控制台中运行此任务时
rake coffee
,它起作用了!但是当我在 schedule.rb 中创建一个计划以每分钟自动发送邮件时,我收到一个错误
hihi rake 中止了!连接被拒绝 - 连接(2)
我跟踪时的错误
rake coffee RAILS_ENV=production --trace
** Invoke coffee (first_time)
** Invoke environment (first_time)
** Invoke rails_admin:disable_initializer (first_time)
** Execute rails_admin:disable_initializer
[RailsAdmin] RailsAdmin initialization disabled by default. Pass SKIP_RAILS_ADMIN_INITIALIZER=false if you need it.
** Execute environment
** Execute coffee
rake aborted!
Connection refused - connect(2)
/home/duykhoa12t/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/smtp.rb:540:in `initialize'
/home/duykhoa12t/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/smtp.rb:540:in `open'
/home/duykhoa12t/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/smtp.rb:540:in `tcp_socket'
/home/duykhoa12t/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/smtp.rb:549:in `block in do_start'
/home/duykhoa12t/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/timeout.rb:68:in `timeout'
/home/duykhoa12t/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/timeout.rb:99:in `timeout'
/home/duykhoa12t/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/smtp.rb:549:in `do_start'
/home/duykhoa12t/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/smtp.rb:519:in `start'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194/gems/mail-2.4.4/lib/mail/network/delivery_methods/smtp.rb:144:in `deliver!'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194/gems/mail-2.4.4/lib/mail/message.rb:2034:in `do_delivery'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194/gems/mail-2.4.4/lib/mail/message.rb:229:in `block in deliver'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194/gems/actionmailer-3.2.8/lib/action_mailer/base.rb:415:in `block in deliver_mail'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/notifications.rb:123:in `block in instrument'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/notifications.rb:123:in `instrument'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194/gems/actionmailer-3.2.8/lib/action_mailer/base.rb:413:in `deliver_mail'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194/gems/mail-2.4.4/lib/mail/message.rb:229:in `deliver'
/home/duykhoa12t/Working/Bbookproject/Code/bbook/Rakefile:10:in `block in <top (required)>'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/home/duykhoa12t/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/bin/rake:19:in `load'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194@global/bin/rake:19:in `<main>'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:14:in `eval'
/home/duykhoa12t/.rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => coffee
我的 schedule.rb(在 /config 中)
set :output, "~/Working/whenever.log"
every 2.minutes do
rake 'coffee'
end
我认为我的邮件配置没有问题,因为当我在控制器和控制台中发送邮件时它起作用了。请帮助我,谢谢!