karmi / retire

A rich Ruby API and DSL for the Elasticsearch search engine
http://karmi.github.com/retire/
MIT License
1.86k stars 533 forks source link

"uninitialized constant" error on import rake task #972

Open callmeed opened 10 years ago

callmeed commented 10 years ago

I'm running tire 0.6.2 with a Rails 3.2x app and ES 0.9.0. I'm trying to use the tire:import:model rake task and get an error as if it can't find my ActiveRecord class.

Command I run:

rake tire:import:model CLASS=Garage RAILS_ENV=staging --trace

Error I get:

** Invoke tire:import:model (first_time)
** Execute tire:import:model
rake aborted!
uninitialized constant Garage
/var/www/smr/shared/bundle/ruby/1.9.1/gems/tire-0.6.2/lib/tire/tasks.rb:95:in `eval'
/var/www/smr/shared/bundle/ruby/1.9.1/gems/tire-0.6.2/lib/tire/tasks.rb:95:in `eval'
/var/www/smr/shared/bundle/ruby/1.9.1/gems/tire-0.6.2/lib/tire/tasks.rb:95:in `block (3 levels) in <top (required)>'
/var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:236:in `call'
/var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:236:in `block in execute'
/var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:231:in `each'
/var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:231:in `execute'
/var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:175:in `block in invoke_with_call_chain'
/usr/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:168:in `invoke_with_call_chain'
/var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:161:in `invoke'
/var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:149:in `invoke_task'
/var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:106:in `each'
/var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:106:in `block in top_level'
/var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:115:in `run_with_threads'
/var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:100:in `top_level'
/var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:78:in `block in run'
/var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:75:in `run'
/var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/bin/rake:33:in `<top (required)>'
/var/www/smr/shared/bundle/ruby/1.9.1/bin/rake:23:in `load'
/var/www/smr/shared/bundle/ruby/1.9.1/bin/rake:23:in `<main>'
Tasks: TOP => tire:import:model
karmi commented 10 years ago

You're running the task incorrectly, please see the documentation.

Also, Tire is deprecated, please use the elasticsearch-rails gem.

On 1. 8. 2014, at 20:33, Erik Dungan notifications@github.com wrote:

I'm running tire 0.6.2 with a Rails 3.2x app and ES 0.9.0. I'm trying to use the tire:import:model rake task and get an error as if it can't find my ActiveRecord class.

Command I run:

rake tire:import:model CLASS=Garage RAILS_ENV=staging --trace

Error I get:

* Invoke tire:import:model (first_time) * Execute tire:import:model rake aborted! uninitialized constant Garage /var/www/smr/shared/bundle/ruby/1.9.1/gems/tire-0.6.2/lib/tire/tasks.rb:95:in eval' /var/www/smr/shared/bundle/ruby/1.9.1/gems/tire-0.6.2/lib/tire/tasks.rb:95:ineval' /var/www/smr/shared/bundle/ruby/1.9.1/gems/tire-0.6.2/lib/tire/tasks.rb:95:in block (3 levels) in <top (required)>' /var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:236:incall' /var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:236:in block in execute' /var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:231:ineach' /var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:231:in execute' /var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:175:inblock in invoke_with_call_chain' /usr/lib/ruby/1.9.1/monitor.rb:211:in mon_synchronize' /var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:168:ininvoke_with_call_chain' /var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/lib/rake/task.rb:161:in invoke' /var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:149:ininvoke_task' /var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:106:in block (2 levels) in top_level' /var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:106:ineach' /var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:106:in block in top_level' /var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:115:inrun_with_threads' /var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:100:in top_level' /var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:78:inblock in run' /var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:165:in standard_exception_handling' /var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/lib/rake/application.rb:75:inrun' /var/www/smr/shared/bundle/ruby/1.9.1/gems/rake-10.1.0/bin/rake:33:in <top (required)>' /var/www/smr/shared/bundle/ruby/1.9.1/bin/rake:23:inload' /var/www/smr/shared/bundle/ruby/1.9.1/bin/rake:23:in `

' Tasks: TOP => tire:import:model — Reply to this email directly or view it on GitHub.

callmeed commented 10 years ago

So, it should be like this? rake environment tire:import CLASS='Article' FORCE=true

My only question is that seems to differ from the outline when you rake -T:

rake tire:import:all                             # Import all indices from `app/models` (or use DIR environment variable)
rake tire:import:model                           # Import data from your model (pass name as CLASS environment variable)
rake tire:index:drop                             # Delete indices passed in the INDEX/INDICES environment variable; separate multiple indices by comma
karmi commented 10 years ago

Yes, exactly!

rake -Tonly lists the tasks themselves, but to load Rails environment, you need to call the environment task as well. There has been discussion about it, and some patches, but in the end, this seemed like the best solution.

The new gem uses that approach as well -- again, please don't use Tire, use the new gem.