Skip to content

Instantly share code, notes, and snippets.

@gbrl
Forked from slothelle/Gemfile
Created October 15, 2016 05:07
Show Gist options
  • Save gbrl/cb18ff3ecc431a696d529f80ad8bf74e to your computer and use it in GitHub Desktop.
Save gbrl/cb18ff3ecc431a696d529f80ad8bf74e to your computer and use it in GitHub Desktop.
Deploying Rails 4 apps with Resque and Redis to Heroku using Unicorn with a Procfile.
# and whatever other gems you need
gem 'resque', '~> 1.24.1'
gem 'unicorn', '~> 4.6.2'
# lives in app root
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
resque: env TERM_CHILD=1 QUEUE=* bundle exec rake resque:work
# lives in config/initializers/redis.rb
# assumes you're using the Redis Cloud addon (NOT Redis TOGO)
if ENV["REDISCLOUD_URL"]
$redis = Resque.redis = Redis.new(:url => ENV["REDISCLOUD_URL"])
end
# lives in lib/tasks/resque.rake
require 'resque/tasks'
task "resque:preload" => :environment
# lives in config/unicorn.rb
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
timeout 15
preload_app true
before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
if defined?(Resque)
Resque.redis.quit
Rails.logger.info('Disconnected from Redis')
end
end
after_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
end
if defined?(Resque)
Rails.logger.info('Connected to Redis')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment