Sidekiq错误:无法连接到服务器:没有这样的文件或目录 [英] Sidekiq error: could not connect to server: No such file or directory
问题描述
我的sidekiq,heroku,redistogo,rails 4配置有问题。我在heroku上有1个dyno和1个工作人员。我只是使用worker来获取外部API的请求。
以下是我在Heroku日志中发现的错误:
app [worker.1]:无法连接到服务器:没有这样的文件或目录
app [worker.1]:Unix域套接字上的连接/var/run/postgresql/.s.PGSQL.5432?
app [worker.1]:服务器在本地运行并接受
这是我的 config / initializers / sidekiq.rb
if Rails.env.production ?
Sidekiq.configure_client do | config |
config.redis = {url:ENV ['REDISTOGO_URL']}
结束
Sidekiq.configure_server do | config |
config.redis = {url:ENV ['REDISTOGO_URL']}
Rails.application.config.after_initialize do
Rails.logger.info(DB Connection Pool size for断开之前的Sidekiq服务器是:#{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#秒
#config ['pool'] = ENV ['WORKER_DB_POOL_SIZE'] || Sidekiq.options [:concurrency]
config ['pool'] = 16
ActiveRecord :: Base.establish_connection(config)
Rails.logger.info(DB Connection Pool现在:#{ActiveRecord :: Base.connection.pool.instance_variable_get('@ size')})
end
end
end
结束
这是我的 Procfile
web:bundle exec puma -C config / puma.rb
worker:bundle exec sidekiq -e production -C config / sidekiq.yml
这是我的 config / sidekiq.yml $ c
$并发:
$并发:
$并发:
:并发: 20
:队列:
- 默认
这是我的 config / initializers / redis.rb
uri = URI.parse(ENV [REDISTOGO_URL ])
REDIS = Redis.new(:url => uri)
是我的 config / puma.rb
workers Integer(ENV ['WEB_CONCURRENCY '] || 2)
threads_count = Integer(ENV ['RAILS_MAX_THREADS'] || 1)
线程threads_count,threads_count
preload_app!
rackup DefaultRackup
端口ENV ['PORT'] || 3000
环境ENV ['RACK_ENV'] || '开发'
before_fork do
将Puma主进程即将分叉,关闭现有活动记录连接。
ActiveRecord :: Base.connection.disconnect!
end
on_worker_boot do
ActiveRecord :: Base.establish_connection
end
根据你的Heroku日志,所以你需要先解决它。
I am having trouble with my sidekiq, heroku, redistogo, rails 4 configuration. I have 1 dyno and 1 worker on heroku. I am just using the worker for a get request to an external api.
Here is the error I get in my Heroku logs:
app[worker.1]: could not connect to server: No such file or directory
app[worker.1]: connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
app[worker.1]: Is the server running locally and accepting
Here is my config/initializers/sidekiq.rb
if Rails.env.production?
Sidekiq.configure_client do |config|
config.redis = { url: ENV['REDISTOGO_URL'] }
end
Sidekiq.configure_server do |config|
config.redis = { url: ENV['REDISTOGO_URL'] }
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'] = 16
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
Here is my Procfile
web: bundle exec puma -C config/puma.rb
worker: bundle exec sidekiq -e production -C config/sidekiq.yml
Here is my config/sidekiq.yml
development:
:concurrency: 5
production:
:concurrency: 20
:queues:
- default
Here is my config/initializers/redis.rb
uri = URI.parse(ENV["REDISTOGO_URL"])
REDIS = Redis.new(:url => uri)
Here is my config/puma.rb
workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 1)
threads threads_count, threads_count
preload_app!
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
before_fork do
puts "Puma master process about to fork. Closing existing Active record connections."
ActiveRecord::Base.connection.disconnect!
end
on_worker_boot do
ActiveRecord::Base.establish_connection
end
As per your Heroku logs, its giving error with PostgreSQL server not with Sidekiq.
So you need to fix it first.
这篇关于Sidekiq错误:无法连接到服务器:没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!