DaemonKit无法加载config / environment文件

时间:2014-05-19 16:14:54

标签: ruby-on-rails ruby rake

我想发起一个rake任务,我写道:

namespace :collections do
  desc "Send again collections notifications"
  task :resend, [:account, :start_timestamp, :stop_timestamp] => [:environment] do |t, args|
    # Code...
  end
end

但是在输入此命令时出现以下错误:

$ bundle exec rake collections:resend --trace
** Invoke collections:resend (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
cannot load such file -- config/environment
/Users/julien/.rvm/gems/ruby-1.9.3-p545/gems/daemon-kit-0.1.8.2/lib/daemon_kit/tasks/environment.rake:4:in `require'
/Users/julien/.rvm/gems/ruby-1.9.3-p545/gems/daemon-kit-0.1.8.2/lib/daemon_kit/tasks/environment.rake:4:in `block in <top (required)>'
/Users/julien/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/rake/task.rb:205:in `call'
/Users/julien/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/rake/task.rb:205:in `block in execute'
/Users/julien/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/rake/task.rb:200:in `each'
/Users/julien/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/rake/task.rb:200:in `execute'
/Users/julien/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/julien/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/julien/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/rake/task.rb:151:in `invoke_with_call_chain'
/Users/julien/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/rake/task.rb:176:in `block in invoke_prerequisites'
/Users/julien/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/rake/task.rb:174:in `each'
/Users/julien/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/rake/task.rb:174:in `invoke_prerequisites'
/Users/julien/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/rake/task.rb:157:in `block in invoke_with_call_chain'
/Users/julien/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/julien/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/rake/task.rb:151:in `invoke_with_call_chain'
/Users/julien/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/rake/task.rb:144:in `invoke'
/Users/julien/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/rake/application.rb:116:in `invoke_task'
/Users/julien/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/rake/application.rb:94:in `block (2 levels) in top_level'
/Users/julien/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/rake/application.rb:94:in `each'
/Users/julien/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/rake/application.rb:94:in `block in top_level'
/Users/julien/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling'
/Users/julien/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/rake/application.rb:88:in `top_level'
/Users/julien/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/rake/application.rb:66:in `block in run'
/Users/julien/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling'
/Users/julien/.rvm/rubies/ruby-1.9.3-p545/lib/ruby/1.9.1/rake/application.rb:63:in `run'
/Users/julien/.rvm/gems/ruby-1.9.3-p545@global/gems/rake-0.9.2.2/bin/rake:32:in `<top (required)>'
/Users/julien/.rvm/gems/ruby-1.9.3-p545/bin/rake:23:in `load'
/Users/julien/.rvm/gems/ruby-1.9.3-p545/bin/rake:23:in `<main>'
/Users/julien/.rvm/gems/ruby-1.9.3-p545/bin/ruby_executable_hooks:15:in `eval'
/Users/julien/.rvm/gems/ruby-1.9.3-p545/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => collections:resend => environment

我无法理解错误,因为我有一个名为config/environment.rb的文件我不知道是否是因为DaemonKit。

1 个答案:

答案 0 :(得分:0)

我最终通过查看DaemonKit代码来解决它,并为此改变了我的任务:

task :resend, [:account, :start_timestamp, :stop_timestamp] do |t, args|
     DaemonKit::Application.running!
     # Code
end

要使其在生产环境中运行,您必须添加环境变量DAEMON_ENV=production