Я запускаю фоновую задачу для многих записей с помощью Rails, Sidekiq, Redis и Clockwork на Heroku, но я продолжаю получать эту ошибку для многих записей, которые он пытается обновить с помощью API:
ActiveRecord::ConnectionTimeoutError: could not obtain a database connection within 5.000 seconds
Вот мои файлы:
Единорог:
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
timeout 15
preload_app true
before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
if defined?(ActiveRecord::Base)
ActiveRecord::Base.connection.disconnect!
end
end
after_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
end
if defined?(ActiveRecord::Base)
config = Rails.application.config.database_configuration[Rails.env]
config['reaping_frequency'] = ENV['DB_REAP_FREQ'] || 10 # seconds
config['pool'] = ENV['DB_POOL'] || 5
ActiveRecord::Base.establish_connection(config)
end
end
База данных:
production:
adapter: postgresql
encoding: unicode
database: production
pool: 25
timeout: 10000
Часы:
every(24.hours, 'Update') do
sites = Site.order(:id).pluck(:id)
Site.each do |site|
UpdatePosts.perform_async(site)
end
end
Обновление сообщений
class UpdatePosts
include Sidekiq::Worker
sidekiq_options retry: false
def perform(site_id)
...
end
end