昨天我在heroku上遇到了一个问题,我的redis连接变得陈旧(heroku + postgres + sidekiq)。确切的错误是:
Re: PG::ConnectionBad: PQconsumeInput() SSL SYSCALL error: EOF detected
我不确定这是什么意思,所以我查了一下这个SOF问题:Heroku + Sidekiq: ActiveRecord::StatementInvalid: PG::UnableToSend: SSL SYSCALL error: EOF detected
我在sidekiq.rb初始化程序中实现了以下内容:
Sidekiq.configure_server do |config|
pool_size = Sidekiq.options[:concurrency] + 2
if defined?(ActiveRecord::Base)
config = Rails.application.config.database_configuration[Rails.env]
config['pool'] = pool_size
ActiveRecord::Base.establish_connection(config)
end
end
然而,然后,heroku告诉我错误的原因是他们结束了,他们把我的DB拿下来进行维护......非常令人困惑。
所以在阅读heroku文档后,我看到我需要这个来设置unicorn服务器:
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!
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
end
我的问题是,这是我系统的正确设置吗?因为我两次调用ActiveRecord :: Base.establish_connection,所以不存在冲突吗?