Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

const_missing with config.threadsafe! #38

Closed
durandom opened this issue Jul 14, 2011 · 1 comment
Closed

const_missing with config.threadsafe! #38

durandom opened this issue Jul 14, 2011 · 1 comment

Comments

@durandom
Copy link

In production I have config.threadsafe! enabled.
This leads to models not accesible in SitemapGenerator:

SitemapGenerator::Sitemap.add_links do |sitemap|
  Monster.where(:weight => weight).find_each do |m|
    sitemap.add m.path.to_s, :changefreq => 'monthly', :lastmod => m.updated_at, :priority => priority
  end
end

produces

bundle exec rake --trace sitemap:refresh CONFIG_FILE="config/sitemap_monsters.rb" 
** Invoke sitemap:refresh (first_time)
** Invoke sitemap:create (first_time)
** Invoke sitemap:require_environment (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute sitemap:require_environment
** Execute sitemap:create
rake aborted!
uninitialized constant Monster
/srv/monsterzoo/shared/bundle/ruby/1.9.1/gems/rake-0.9.2/lib/rake/ext/module.rb:36:in `const_missing'
config/sitemap_monsters.rb:26:in `block in run'
/srv/monsterzoo/shared/bundle/ruby/1.9.1/gems/sitemap_generator-2.0.1/lib/sitemap_generator/interpreter.rb:47:in `eval'
/srv/monsterzoo/shared/bundle/ruby/1.9.1/gems/sitemap_generator-2.0.1/lib/sitemap_generator/link_set.rb:33:in `create'
/srv/monsterzoo/shared/bundle/ruby/1.9.1/gems/sitemap_generator-2.0.1/lib/sitemap_generator/link_set.rb:43:in `add_links'
/srv/monsterzoo/shared/bundle/ruby/1.9.1/gems/sitemap_generator-2.0.1/lib/sitemap_generator.rb:27:in `method_missing'
config/sitemap_monsters.rb:8:in `run'
/srv/monsterzoo/shared/bundle/ruby/1.9.1/gems/sitemap_generator-2.0.1/lib/sitemap_generator/interpreter.rb:65:in `instance_eval'
/srv/monsterzoo/shared/bundle/ruby/1.9.1/gems/sitemap_generator-2.0.1/lib/sitemap_generator/interpreter.rb:65:in `run'
/srv/monsterzoo/shared/bundle/ruby/1.9.1/gems/sitemap_generator-2.0.1/tasks/sitemap_generator_tasks.rake:41:in `block (2 levels) in <top (required)>'
/srv/monsterzoo/shared/bundle/ruby/1.9.1/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
/srv/monsterzoo/shared/bundle/ruby/1.9.1/gems/rake-0.9.2/lib/rake/task.rb:205:in `block in execute'
/srv/monsterzoo/shared/bundle/ruby/1.9.1/gems/rake-0.9.2/lib/rake/task.rb:200:in `each'
/srv/monsterzoo/shared/bundle/ruby/1.9.1/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
/srv/monsterzoo/shared/bundle/ruby/1.9.1/gems/rake-0.9.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/srv/monsterzoo/shared/bundle/ruby/1.9.1/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/srv/monsterzoo/shared/bundle/ruby/1.9.1/gems/rake-0.9.2/lib/rake/task.rb:176:in `block in invoke_prerequisites'
/srv/monsterzoo/shared/bundle/ruby/1.9.1/gems/rake-0.9.2/lib/rake/task.rb:174:in `each'
/srv/monsterzoo/shared/bundle/ruby/1.9.1/gems/rake-0.9.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/srv/monsterzoo/shared/bundle/ruby/1.9.1/gems/rake-0.9.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/srv/monsterzoo/shared/bundle/ruby/1.9.1/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/srv/monsterzoo/shared/bundle/ruby/1.9.1/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
/srv/monsterzoo/shared/bundle/ruby/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:112:in `invoke_task'
/srv/monsterzoo/shared/bundle/ruby/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:90:in `block (2 levels) in top_level'
/srv/monsterzoo/shared/bundle/ruby/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:90:in `each'
/srv/monsterzoo/shared/bundle/ruby/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:90:in `block in top_level'
/srv/monsterzoo/shared/bundle/ruby/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/srv/monsterzoo/shared/bundle/ruby/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level'
/srv/monsterzoo/shared/bundle/ruby/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:62:in `block in run'
/srv/monsterzoo/shared/bundle/ruby/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/srv/monsterzoo/shared/bundle/ruby/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
/srv/monsterzoo/shared/bundle/ruby/1.9.1/gems/rake-0.9.2/bin/rake:32:in `<top (required)>'
/srv/monsterzoo/shared/bundle/ruby/1.9.1/bin/rake:19:in `load'
/srv/monsterzoo/shared/bundle/ruby/1.9.1/bin/rake:19:in `<main>'
Tasks: TOP => sitemap:refresh => sitemap:create

The only workaround is to disable threadsafety for rake tasks in my environment:

config.threadsafe! unless $rails_rake_task
@kjvarga
Copy link
Owner

kjvarga commented Jul 14, 2011

Hi @durandom,

I'm afraid this is a general Rails issue with class loading and threadsafe. Check out these threads:

http://groups.google.com/group/rubyonrails-core/browse_thread/thread/b13dbe0b8f12b7dc
http://www.multunus.com/2010/11/rails-threadsafe-and-rake-task/

Cheers,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants