Search code examples
ruby-on-railsruby-on-rails-3rakeresque

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


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

Solution

  • 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.