Reputation: 7400
I have installed resque correctly, but to process all queues I need to run
rake resque:work QUEUE='*'
The problem is that I need to keep the terminal window opened, otherwise resque:work won't works.
Do you know a way to auto-run that rake command every time I run "rails server" ?
I'm on Localhost
lib/tasks/resque.rake
require 'resque/tasks'
task "resque:setup" => :environment do
ENV['QUEUE'] = "*"
end
Upvotes: 9
Views: 19379
Reputation: 11811
Edit: Answer from 2012! Seems that this works just for Rails 2!
Add an initializer in config/initializers with something like this:
Rake::Task["resque:work QUEUE='*'"].invoke
Not tested!
Upvotes: 2
Reputation: 1517
Instead of calling the invoke function, you can use a gem like foreman that can invoke all the other tasks. This is useful if you are looking to have a largely platform neutral solution and also while deploying into cloud. Your Procfile can have the following contents:
web: bundle exec thin start -p $PORT
worker: bundle exec rake resque:work QUEUE=*
clock: bundle exec rake resque:scheduler
Source:introduction to foreman.
Now to start the server, you just have to issue foreman start command which forks off child threads to perform individual work.
Upvotes: 12
Reputation: 155
The best way to do it is
ENV['QUEUE'] = "*"
Rake::Task["resque:work"].invoke
Upvotes: 0