2011-10-30 125 views
1

我有一个rake任务,可以在dev env中正常运行,但不能在prod中运行。红宝石Rake与rails缺少生产,但在开发环境中工作

task :sample_test_quote => :environment do 

    QuoterTester.test 

end 

QuoterTester是一个带有类方法测试的模型类。

运行下开发任务工作正常,像这样:

rake sample_test_quote 

而督促下,我得到这个:

$ RAILS_ENV=production rake sample_test_quote --trace 
** Invoke sample_test_quote (first_time) 
** Invoke environment (first_time) 
** Execute environment 
** Execute sample_test_quote 
rake aborted! 
uninitialized constant QuoterTester 
org/jruby/RubyModule.java:2590:in `const_missing' 
/Users/kimptoc/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/ext/module.rb:36:in `const_missing' 
org/jruby/RubyMethod.java:133:in `call' 
/Users/kimptoc/Documents/ruby/ecom/ecom1/lib/tasks/sample_test_quote.rake:3:in `(root)' 
org/jruby/RubyProc.java:270:in `call' 
org/jruby/RubyProc.java:220:in `call' 
/Users/kimptoc/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `execute' 
org/jruby/RubyArray.java:1612:in `each' 
/Users/kimptoc/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute' 
/Users/kimptoc/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `invoke_with_call_chain' 
/Users/kimptoc/.rvm/rubies/jruby-1.6.5/lib/ruby/1.8/monitor.rb:191:in `mon_synchronize' 
/Users/kimptoc/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain' 
/Users/kimptoc/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke' 
/Users/kimptoc/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task' 
/Users/kimptoc/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `top_level' 
org/jruby/RubyArray.java:1612:in `each' 
/Users/kimptoc/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `top_level' 
/Users/kimptoc/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling' 
/Users/kimptoc/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level' 
/Users/kimptoc/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `run' 
/Users/kimptoc/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling' 
/Users/kimptoc/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run' 
/Users/kimptoc/.rvm/gems/[email protected]/gems/rake-0.9.2.2/bin/rake:33:in `(root)' 
org/jruby/RubyKernel.java:1063:in `load' 
/Users/kimptoc/.rvm/gems/[email protected]/bin/rake:19:in `(root)' 
Tasks: TOP => sample_test_quote 

我使用JRuby 1.6.5,MySQL的 - 督促和dev database.yml几乎相同的设置。还使用Gemfile - 见下文。

从这个question,我猜测它的项目中的一个类的问题。

那么,有关如何追踪哪些类的提示?

奇怪的是,rails服务器/控制台都在prod环境中工作 - 我本来期望他们也会失败。

TIA,克里斯

这里是Gemfile中我使用

source 'http://rubygems.org' 

gem 'rake' 

gem 'rails', '3.1.1' 

if defined?(JRUBY_VERSION) 
    #jruby gems 
    gem 'activerecord-jdbc-adapter' 
    #gem 'activerecord-jdbc-adapter', :git => "https://github.com/jruby/activerecord-jdbc-adapter.git" 
    #gem 'activerecord-jdbcmysql-adapter' 
    #gem 'activerecord-jdbcmysql-adapter', :path => '../../libs/activerecord-jdbc-adapter.kimptoc' 
    #gem 'activerecord-jdbcmysql-adapter',:git => "https://github.com/kimptoc/activerecord-jdbc-adapter.git" 
    gem 'activerecord-jdbcmysql-adapter',:git => "https://github.com/jruby/activerecord-jdbc-adapter.git" 
    gem "jruby-openssl" 
else 
    #non jruby gems 
    gem 'mysql' 
end 

gem "letter_opener", :group => :development 



gem "mechanize", "1.0.0" 

gem "nokogiri","1.4.6" 

gem "roo" 
gem "rubyzip" 

gem "parallel" 


gem "savon", "=0.7.9" 


group :development, :test do 
    gem "rcov" 
    gem "pry" 
end 

gem "fastercsv" 

gem "xml-simple" 

gem "rabl" 

gem 'bcrypt-ruby', :require => 'bcrypt' 

gem 'newrelic_rpm' 

# Gems used only for assets and not required 
# in production environments by default. 
group :assets do 
    gem 'sass-rails', " ~> 3.1.0" 
    gem 'coffee-rails', " ~> 3.1.0" 
    gem 'uglifier' 
end 

gem 'jquery-rails' 

gem "acts_as_executor", :git => "https://github.com/philostler/acts_as_executor.git" 

gem 'rufus-scheduler' 

这里是实际的宝石:

actionmailer (3.1.1) 
actionpack (3.1.1) 
activemodel (3.1.1) 
activerecord (3.1.1) 
activeresource (3.1.1) 
activesupport (3.1.1) 
addressable (2.2.6) 
arel (2.2.1) 
bcrypt-ruby (3.0.1 java) 
bouncy-castle-java (1.5.0146.1) 
builder (3.0.0) 
bundler (1.0.21) 
coderay (0.9.8) 
coffee-rails (3.1.1) 
coffee-script (2.2.0) 
coffee-script-source (1.1.2) 
crack (0.3.1) 
erubis (2.7.0) 
execjs (1.2.9) 
fastercsv (1.5.4) 
google-spreadsheet-ruby (0.1.5) 
hike (1.2.1) 
hoe (2.12.3) 
i18n (0.6.0) 
jquery-rails (1.0.16) 
jruby-launcher (1.0.9 java) 
jruby-openssl (0.7.4) 
json (1.6.1 java) 
launchy (2.0.5) 
letter_opener (0.0.2) 
mail (2.3.0) 
mechanize (1.0.0) 
method_source (0.6.6) 
mime-types (1.17.1, 1.16) 
multi_json (1.0.3) 
newrelic_rpm (3.2.0) 
nokogiri (1.4.6 java) 
oauth (0.4.5) 
parallel (0.5.9) 
polyglot (0.3.2) 
pry (0.9.6.2 java) 
rabl (0.5.0, 0.3.0) 
rack (1.3.5, 1.3.4) 
rack-cache (1.1) 
rack-mount (0.8.3) 
rack-ssl (1.3.2) 
rack-test (0.6.1) 
rails (3.1.1) 
railties (3.1.1) 
rake (0.9.2.2, 0.9.2) 
rcov (0.9.11 java) 
rdoc (3.11, 3.10) 
roo (1.9.5) 
ruby-ole (1.2.11.2) 
ruby_parser (2.0.6) 
rubyzip (0.9.4) 
rufus-scheduler (2.0.12) 
sass (3.1.10) 
sass-rails (3.1.4) 
savon (0.7.9) 
sexp_processor (3.0.7) 
slop (2.1.0) 
spoon (0.0.1) 
spreadsheet (0.6.5.9) 
sprockets (2.0.3, 2.0.2) 
thor (0.14.6) 
tilt (1.3.3) 
treetop (1.4.10) 
tzinfo (0.3.30) 
uglifier (1.0.4, 1.0.3) 
weakling (0.0.4 java) 
xml-simple (1.1.1) 
+1

你可以显示rake任务和完整的错误输出吗? –

+0

谢谢道格拉斯 - 细节上有点短:) –

+1

你的gemfile的生产部分是否有gem set? –

回答

7

这是耙任务运行时,一个相当普遍的问题在生产模式下,如果config.threadsafe!已启用,它应该用于JRuby应用程序。

一个可能的解决方法是编辑您的环境,以便config.threadsafe!仅在您运行Rake任务(您可以为此构建自己的环境变量)时被禁用。

+0

很多谢谢,听起来不错 - 今晚我会回到家,当我回家时 –

+2

就是这样 - 我现在已经用“if defined?(Rails :: Server)”包裹了配置设置,并且它可以很好地与Rake配合使用。 –

+2

很高兴听到它!分享JRuby的爱也很好:-) – Scott