Adjustreact
daiao 5 years ago
parent fd8f6014a1
commit a2fb0a247c

@ -38,9 +38,7 @@ namespace :subjects do
end
subjects.find_in_batches(batch_size: 50) do |s|
Parallel.in_processes(4) do |i|
end
str = []
Parallel.each_with_index(s, in_processes: 4) do |subject, index|
puts("---------------------data_statistic: #{subject.id}")
Rails.logger.info("---------------------data_statistic: #{subject.id}")
@ -54,11 +52,10 @@ namespace :subjects do
"'#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')")
puts "index: #{index}; worker_number: #{Parallel.worker_number}"
puts "####str: #{str}"
if str.size == 100 || subject == s.last
if subject == s.last
sql = "REPLACE INTO subject_records(#{column_value}) VALUES #{str.uniq.join(",")}"
puts sql
ActiveRecord::Base.connection.execute sql
str = []
end
end
end

Loading…
Cancel
Save