/ RAILS

Resque Setup Development Mode

This tutorial will guide you setting up Resque locally in development mode with Multiple workers and how to use with Rails application to process background jobs.

What is Resque?

You might want to know what is Resque before we begin with commands/flow to set it up locally.

redis

It uses Redis as a backend, thus you need to understand Redis architecture to know how resque-workers process background jobs.

Steps

  1. Install Redis
curl -O https://download.redis.io/redis-stable.tar.gz
tar -xvzf redis-stable.tar.gz
rm redis-stable.tar.gz
cd redis-stable
make
sudo make install

This is fine guide to help installing Redis

2. Start Redis server

redis-server start

This will start redis server for you and listen on port 6379

3. Create setup.rb initializers file

uri = URI.parse('redis://localhost:6379/')
Resque.redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password, :thread_safe => true)
Resque.redis.namespace = "redis namespace for your app"

This will connect to redis server which was listening on port 6379

4. Start resque workers

rake resque:work

This will start single working listening to all queues.

If you want to start multiple workers -

rake resque:workers COUNT=3

This will start 3 workers and will process jobs placed on any queue from your Rails application

Now whenever you enqueue jobs, these workers will process jobs in the background and you can see the logs for the same as well.

Let us know through comments if you face any difficulty setting up in development environment.

akshay

Akshay Mohite

Hi there! I am a Ruby on Rails & ReactJS Enthusiast, building some cool products at DTree Labs.

Read More
Buy me a coffee