Skip to content

Instantly share code, notes, and snippets.

@snatchev
Created October 26, 2011 14:08
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save snatchev/1316470 to your computer and use it in GitHub Desktop.
Save snatchev/1316470 to your computer and use it in GitHub Desktop.
resque worker devise not eager loading
❷ > QUEUE=* rake resque:work --trace
** Invoke resque:work (first_time)
** Invoke resque:preload (first_time)
** Invoke resque:setup (first_time)
** Execute resque:setup
** Execute resque:preload
rake aborted!
No such file to load -- devise/confirmations_controller
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:306:in `rescue in depend_on'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:301:in `depend_on'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:214:in `require_dependency'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/railties-3.1.1/lib/rails/engine.rb:417:in `block (2 levels) in eager_load!'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/railties-3.1.1/lib/rails/engine.rb:416:in `each'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/railties-3.1.1/lib/rails/engine.rb:416:in `block in eager_load!'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/railties-3.1.1/lib/rails/engine.rb:414:in `each'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/railties-3.1.1/lib/rails/engine.rb:414:in `eager_load!'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/railties-3.1.1/lib/rails/application/railties.rb:8:in `each'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/railties-3.1.1/lib/rails/application/railties.rb:8:in `all'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/railties-3.1.1/lib/rails/engine.rb:412:in `eager_load!'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/resque-1.19.0/lib/resque/tasks.rb:47:in `block (2 levels) in <top (required)>'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/rake-0.9.2/lib/rake/task.rb:205:in `block in execute'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/rake-0.9.2/lib/rake/task.rb:200:in `each'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/rake-0.9.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/stefan/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/rake-0.9.2/lib/rake/task.rb:176:in `block in invoke_prerequisites'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/rake-0.9.2/lib/rake/task.rb:174:in `each'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/rake-0.9.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/rake-0.9.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain'
/Users/stefan/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/rake-0.9.2/lib/rake/application.rb:112:in `invoke_task'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/rake-0.9.2/lib/rake/application.rb:90:in `block (2 levels) in top_level'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/rake-0.9.2/lib/rake/application.rb:90:in `each'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/rake-0.9.2/lib/rake/application.rb:90:in `block in top_level'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/rake-0.9.2/lib/rake/application.rb:62:in `block in run'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/gems/rake-0.9.2/bin/rake:32:in `<top (required)>'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/bin/rake:19:in `load'
/Users/stefan/.rvm/gems/ruby-1.9.2-p290@my-rails-project/bin/rake:19:in `<main>'
Tasks: TOP => resque:work => resque:preload
@snatchev
Copy link
Author

This error was resolved, by running
$> QUEUE=* rake environment resque:work

a cleaner solution was to define a rake task:

task "resque:setup" => :environment do
  ENV['QUEUE'] ||= '*'
  #for redistogo on heroku http://stackoverflow.com/questions/2611747/rails-resque-workers-fail-with-pgerror-server-closed-the-connection-unexpectedl
  Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection }
end

and now
rake resque:work
works properly

@davekapp
Copy link

davekapp commented Nov 3, 2011

Thanks for the tip - I just ran into this same issue and your fixes worked fine for me as well.

@darron
Copy link

darron commented Jan 16, 2012

Yes - thanks a ton - worked great for me too.

@baash05
Copy link

baash05 commented Mar 8, 2012

THANKS.. oh thanks soo much.

@mhuggins
Copy link

Thank you for sharing this! For anyone else who comes across this, I changed this line:

ENV['QUEUE'] = '*'

to this:

ENV['QUEUE'] ||= '*'

That way I can still specify queue names from the command line if necessary, falling back to all queues otherwise.

@snatchev
Copy link
Author

@mhuggins, good idea. I've updated my initial comment with your suggestion.

@nfedyashev
Copy link

thanks a lot!

@kensreng
Copy link

yes !!!
it also work fine for me !!

@dashdotat
Copy link

Brilliant, thank you!

@ideomix
Copy link

ideomix commented Oct 10, 2012

thaaaaaaaaaank you!!!!

@omnikron
Copy link

@snatchev Brilliant, thank you!

@jeperkins4
Copy link

Excellent! Saved me a whole bunch of time debugging...

@the-architect
Copy link

thanks! was just running into this issue :)

@constantine-nikolaou
Copy link

👍 thanks

@raecoo
Copy link

raecoo commented Oct 11, 2013

Works well. 😄 Thanks a lot.

@rafiamafia
Copy link

This is an issue if you are adding Resque to a Rails app. As we know Resque does not require Rails. The solution allows you to load the entire Rails environment when you start up the workers. I did not see this issue when demoing Resque on a stand alone Ruby application.

@siruguri
Copy link

And if you're using foreman, the corresponding syntax in your Procfile, that will also work, is

resque: bundle exec rake environment resque:work

In my case, I used .env to set my QUEUE environment variable:

QUEUE='*'

@chrishough
Copy link

thank you for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment