How to run "rake resque:work QUEUE=*" when Rails server boots?

sparkle picture sparkle · Nov 10, 2012 · Viewed 16.5k times · Source

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

Answer

Sumit Bisht picture Sumit Bisht · Aug 16, 2013

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.