【问题标题】:Sidekiq error: could not connect to server: No such file or directorySidekiq 错误:无法连接到服务器:没有这样的文件或目录
【发布时间】:2017-03-20 21:43:07
【问题描述】:

我的 sidekiq、heroku、redistogo、rails 4 配置有问题。我在heroku上有1个测功机和1个工人。我只是使用工作人员对外部 api 的获取请求。

这是我在 Heroku 日志中遇到的错误:

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

这是我的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  

这是我的Procfile

web: bundle exec puma -C config/puma.rb
worker: bundle exec sidekiq -e production -C config/sidekiq.yml

这是我的config/sidekiq.yml

development:  
  :concurrency: 5
production:  
  :concurrency: 20
:queues:
  - default

这是我的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 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  

【问题讨论】:

  • 到目前为止,我已经删除了 Rails.application.config.after_initialize do 块并将我的生产并发更改为 5 并且它正在工作。
  • 这看起来应用程序无法连接到 postgres 服务器。我认为不是sidekiq问题。你在heroku中添加了postgres服务器了吗?
  • 你是怎么解决这个问题的?我遇到了同样的问题,只有在尝试启动 sidekiq 时才会发生

标签: ruby-on-rails heroku sidekiq puma worker


【解决方案1】:

根据您的 Heroku 日志,它在 PostgreSQL 服务器而不是 Sidekiq 上给出错误。

所以你需要先修复它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-29
    • 2015-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-08
    • 2018-01-14
    • 1970-01-01
    相关资源
    最近更新 更多