任何想法是什么导致日志中出现此消息?
'[COBALT] could not receive data from client: Connection reset by peer'.
我认为这是 before_fork/after_fork 过程之一的问题——或者仅仅是 Heroku 问题与此代码无关?
resque.rb
require 'resque/server'
ENV["REDIS_URL"] ||= "redis://localhost:6379/"
uri = URI.parse(ENV["REDIS_URL"])
$redis = Redis.new(host: uri.host, port: uri.port, password: uri.password)
Resque.redis = $redis
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }
独角兽.rb
# config/unicorn.rb
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
timeout 20
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
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
if defined?(Resque)
Resque.redis = ENV['REDIS_URL']
Rails.logger.info('Connected to Redis')
end
end