我正在使用whenever
gem每日发送电子邮件任务。
我在RAKEFILE名称coffee中创建了一个rake任务。这是我的任务代码:
task :coffee => :environment do
ReservationBooksNotify.notify.deliver
puts "hihi"
end
当我在控制台中运行此任务时
rake coffee
,它有效!
但是当我在schedule.rb中创建一个时间表以便每分钟自动发送邮件时,我收到错误
日冰 耙子流产了! 连接被拒绝 - 连接(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
我认为我的邮件程序配置没有问题,因为它在我在控制器和控制台中发送邮件时起作用。请帮助我,谢谢!
答案 0 :(得分:0)
最后,我不知道为什么,我尝试rake assets: precompile
,然后重启服务器,一切正常!