Resque depends on Redis, so first install Redis locally to be able to work on your project...
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 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.
Again, first install Redis, I added this Add-on to my project: Heroku Redis
Add a new Config Variable REDIS_URL
having the location of your Heroku Redis (which you will receive after installing the add-on)
git push heroku master
At "Resources" you will find a new Dyno: resque
. Enable this one :)