Skip to content

Instantly share code, notes, and snippets.

@rogiervandenberg
Last active July 11, 2016 07:56
Show Gist options
  • Save rogiervandenberg/0fc6095df1510947072053a9010c5a24 to your computer and use it in GitHub Desktop.
Save rogiervandenberg/0fc6095df1510947072053a9010c5a24 to your computer and use it in GitHub Desktop.
Setup Resque with Rails 4 on Heroku and locally

Setup Resque on Heroku for Rails 4

Resque depends on Redis, so first install Redis locally to be able to work on your project...

Install Redis locally on Mac

To install Redis locally, use the following approach on Mac OS X (using Homebrew). $ brew install redis

To test your install, firstly ensure that the Redis server is running. $ redis-server

Add Resque to your Rails project

Add these two gems to your Gemfile:

gem 'resque', "~> 1.22.0"
gem 'redis'

Run bundle

bundle install

To let Rails know we use Resque for our queues, add this line:

config.active_job.queue_adapter = :resque

Make a /lib/tasks/resque.rake file and add, to make sure your environment is available to your worker:

require 'resque/tasks'

task "resque:preload" => :environment

Add this line to your Procfile:

resque: env TERM_CHILD=1 RESQUE_TERM_TIMEOUT=7 QUEUE=* bundle exec rake resque:work

Make sure the location of Redis is known to your application (Needed for Heroku), e.g. in your .ENV file:

REDIS_URL=redis://127.0.0.1:6379

Make sure the location of Redis is explicit. Create a new file /config/initializers/redis.rb and add:

$redis = Redis.new(url: ENV["REDIS_URL"])

When launching your server now, background jobs will be processed in parallel. Make sure you have the redis server running simultaneously.

Install Resque on Heroku

Again, first install Redis, I added this Add-on to my project: Heroku Redis

REDIS_URL

Add a new Config Variable REDIS_URL having the location of your Heroku Redis (which you will receive after installing the add-on)

Deploy your application to Heroku

git push heroku master

Enable your worker

At "Resources" you will find a new Dyno: resque. Enable this one :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment