问题
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
回答1:
As per your Heroku logs, its giving error with PostgreSQL server not with Sidekiq.
So you need to fix it first.
来源:https://stackoverflow.com/questions/42756028/sidekiq-error-could-not-connect-to-server-no-such-file-or-directory