Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 290
sparkle Avatar asked Nov 10 '12 22:11

sparkle


People also ask

How do I start resque rails?

Then restart your Rails server. Open up http://localhost:3000/resque in a browser to check out the web running jobs and schedules. If you are using Resque-scheduler then it will add more options for you in the resque-web UI. Those options allows you to view queues and manually start queuing.

What is Resque?

Resque (pronounced like "rescue") is a Redis-backed library for creating background jobs, placing those jobs on multiple queues, and processing them later.


2 Answers

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.

like image 125
Sumit Bisht Avatar answered Oct 08 '22 21:10

Sumit Bisht


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!

like image 39
BvuRVKyUVlViVIc7 Avatar answered Oct 08 '22 20:10

BvuRVKyUVlViVIc7