我试图使用以下方法在Heroku工作者中初始化Sidekiq:
if Rails.env.production?
Sidekiq.configure_client do |config|
config.redis = { url: ENV['REDISCLOUD_URL'], size: 2 }
end
Sidekiq.configure_server do |config|
config.redis = { url: ENV['REDISCLOUD_URL'], size: 10 }
Rails.application.config.after_initialize do
Rails.logger.info("DB Connection Pool size for Sidekiq Server before disconnect is: #{ActiveRecord::Base.connection.pool.instance_variable_get('@size')}")
ActiveRecord::Base.connection_pool.disconnect!
ActiveSupport.on_load(:active_record) do
config = Rails.application.config.database_configuration[Rails.env]
config['reaping_frequency'] = ENV['DATABASE_REAP_FREQ'] || 10 # seconds
# config['pool'] = ENV['WORKER_DB_POOL_SIZE'] || Sidekiq.options[:concurrency]
config['pool'] = 8
ActiveRecord::Base.establish_connection(config)
Rails.logger.info("DB Connection Pool size for Sidekiq Server is now: #{ActiveRecord::Base.connection.pool.instance_variable_get('@size')}")
end
end
end
end
但是我的日志中有以下内容:
2017-04-12T22:33:20.435939+00:00 heroku[worker.1]: State changed from crashed to starting
2017-04-12T22:33:23.510593+00:00 heroku[worker.1]: Starting process with command `bundle exec sidekiq -e production -C config/sidekiq.yml`
2017-04-12T22:33:24.049032+00:00 heroku[worker.1]: State changed from starting to up
2017-04-12T22:33:26.528756+00:00 app[worker.1]: 4 TID-otpsq87bc INFO: Booting Sidekiq 4.2.10 with redis options {:url=>"redis://rediscloud:REDACTED@redis-14870.c1.eu-west-1-3.ec2.cloud.redislabs.com:14870", :size=>20}
2017-04-12T22:33:27.606408+00:00 heroku[worker.1]: State changed from up to crashed
2017-04-12T22:33:27.590348+00:00 heroku[worker.1]: Process exited with status 1
2017-04-12T22:33:27.506096+00:00 app[worker.1]: I, [2017-04-12T22:33:27.505980 #4] INFO -- : DB Connection Pool size for Sidekiq Server before disconnect is: 5
2017-04-12T22:33:27.509172+00:00 app[worker.1]: could not connect to server: Connection refused
2017-04-12T22:33:27.509174+00:00 app[worker.1]: Is the server running on host "localhost" (127.0.0.1) and accepting
2017-04-12T22:33:27.509175+00:00 app[worker.1]: TCP/IP connections on port 5432?
有没有人知道出了什么问题?
答案 0 :(得分:0)
它正在寻找本地主机上的Postgres:5432。
答案 1 :(得分:0)
尝试在Heroku上运行Sidekiq时遇到了同样的问题。我通过在database.yml中的url: <%= ENV['DATABASE_URL'] %>
下添加production:
来修复它。