ruby rake with rails在生产中缺少常量,但在开发环境中工作

时间:2011-10-30 22:56:06

标签: ruby ruby-on-rails-3.1 rake jruby rake-task

我有一个rake任务,在dev env中运行正常,但不是prod。

task :sample_test_quote => :environment do

  QuoterTester.test

end

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

在dev下运行任务可以正常工作,如下所示:

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/jruby-1.6.5@global/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/jruby-1.6.5@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `execute'
org/jruby/RubyArray.java:1612:in `each'
/Users/kimptoc/.rvm/gems/jruby-1.6.5@global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/kimptoc/.rvm/gems/jruby-1.6.5@global/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/jruby-1.6.5@global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/kimptoc/.rvm/gems/jruby-1.6.5@global/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/kimptoc/.rvm/gems/jruby-1.6.5@global/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Users/kimptoc/.rvm/gems/jruby-1.6.5@global/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/jruby-1.6.5@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `top_level'
/Users/kimptoc/.rvm/gems/jruby-1.6.5@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/kimptoc/.rvm/gems/jruby-1.6.5@global/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Users/kimptoc/.rvm/gems/jruby-1.6.5@global/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `run'
/Users/kimptoc/.rvm/gems/jruby-1.6.5@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/kimptoc/.rvm/gems/jruby-1.6.5@global/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/kimptoc/.rvm/gems/jruby-1.6.5@global/gems/rake-0.9.2.2/bin/rake:33:in `(root)'
org/jruby/RubyKernel.java:1063:in `load'
/Users/kimptoc/.rvm/gems/jruby-1.6.5@p-ecom1-rails311/bin/rake:19:in `(root)'
Tasks: TOP => sample_test_quote

我正在使用JRuby 1.6.5,使用mysql - prod和dev database.yml几乎是相同的设置。还使用Gemfile - 见下文。

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

那么,关于如何追踪哪个班级的任何提示?

奇怪的是,rails服务器/控制台都在prod env中工作 - 我原本以为它们也会失败。

TIA,Chris

这是我正在使用的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 个答案:

答案 0 :(得分:7)

如果启用了config.threadsafe!,则在生产模式下运行Rake任务时这是一个相当常见的问题,它应该适用于JRuby应用程序。

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