Sidekiq错误:无法连接到服务器:没有这样的文件或目录

时间:2017-03-13 03:05:25

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

我遇到了我的sidekiq,heroku,redistogo,rails 4配置问题。我在heroku上有1个dyno和1个worker。我只是使用worker来获取外部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  

1 个答案:

答案 0 :(得分:1)

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

所以你需要先修复它。