In your Gemfile
gem 'resque', :require => 'resque/server'
Run bundle
bundle install
create lib/redis_connection.rb
class RedisConnection
def self.close
connection.quit
end
def self.connection
@connection ||= new_connection
end
private
def self.new_connection
Redis.new(:host => Settings.redis.host,
:port => Settings.redis.port,
:password => Settings.redis.password,
:thread_safe => true)
end
end
Note: These settings are referenced from the settings.yml file via SettingsLogic gem
On the terminal
heroku config:set REDIS_HOST=ray.redistogo.com --remote stage
heroku config:set REDIS_PORT=9286 --remote stage
heroku config:set REDIS_PASSWORD=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx --remote stage
staging:
<<: *defaults
redis:
host: <%= ENV["REDIS_HOST"] %>
port: <%= ENV["REDIS_PORT"] %>
password: <%= ENV["REDIS_PASSWORD"] %>
Add/edit this line in config/application.rb
config.autoload_paths += %W(#{config.root}/lib #{config.root}/lib/**/*)
create a file of lib/tasks/resque.rake
require "resque/tasks"
task "resque:setup" => :environment do
Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection }
end
create config/initializers/resque.rb
Resque.redis = RedisConnection.connection
create account at RedisToGo https://redistogo.com
get instance info at https://redistogo.com/instances
- requirepass
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
- port
9286
- host
ray.redistogo.com
create Procfile.local
for testing, development on Local
redis: redis-server
worker: env QUEUE=* bundle exec rake environment resque:work
create Procfile
for staging, production on Heroku
web: thin start -p $PORT
worker: env QUEUE=* bundle exec rake resque:work
Add line to config/routes.rb
mount Resque::Server, :at => "/resque"
On the terminal
heroku ps:scale worker=1 --remote stage
Best example I've seen online. Thanks!