Last active
December 18, 2018 02:43
-
-
Save slothelle/50ca2c6d6f78656e267a to your computer and use it in GitHub Desktop.
Deploying Rails 4 apps with Resque and Redis to Heroku using Unicorn with a Procfile.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# and whatever other gems you need | |
gem 'resque', '~> 1.24.1' | |
gem 'unicorn', '~> 4.6.2' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lives in lib/tasks/resque.rake | |
require 'resque/tasks' | |
task "resque:preload" => :environment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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
This solves my 6 hours problem.