ruby-on-rails - Sidekiq错误: could not connect to server: No such file or directory

标签 ruby-on-rails heroku sidekiq puma worker

我的 sidekiq、heroku、redistogo、rails 4 配置遇到问题。我在 Heroku 上有 1 台 dyno 和 1 台工作人员。我只是使用工作程序向外部 api 发出 get 请求。

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

最佳答案

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

所以你需要先修复它。

关于ruby-on-rails - Sidekiq错误: could not connect to server: No such file or directory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42756028/

相关文章:

ruby-on-rails - 如何让 RVM 在我的 Mac 终端中被识别?

ruby-on-rails - 为什么主页因微博提交失败而中断 - Michael Hartl Rails 教程

jquery - 浏览器上一个按钮和模式窗口

ruby-on-rails - Heroku 模式加载 : Permission denied for database "postgres" User

node.js - 扩展 Node.js 应用程序 - 哪个提供商?

ruby-on-rails - Elastic Beanstalk Redis 失败,Web 应用程序无响应

ruby-on-rails - 如何为 Rails 事件记录中的 JSON 列/属性设置默认值?

heroku - 角色 "username"heroku Nodejs 的连接过多 - 什么是 yobuko?

ruby-on-rails - sidekiq 后台作业发送电子邮件和 heroku worker

ruby - 如何在特定队列中推送作业并使用 sidekiq 限制工作人员数量?