From 8655498b9cb5ba44ec158f24be70a0eee20fa5a3 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 13 Feb 2020 14:30:19 +0800 Subject: [PATCH] 1 --- lib/tasks/statistic_subject_info.rake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tasks/statistic_subject_info.rake b/lib/tasks/statistic_subject_info.rake index d188011a7..2c379eb26 100644 --- a/lib/tasks/statistic_subject_info.rake +++ b/lib/tasks/statistic_subject_info.rake @@ -10,7 +10,7 @@ namespace :subjects do subjects.find_in_batches(batch_size: 50) do |s| str = "" buffer_size = 0 - Parallel.each(s, in_processes: 4) do |subject| + Parallel.each_with_index(s, in_processes: 4) do |subject, index| buffer_size += 1 str += ", " unless str.empty? puts("---------------------data_statistic: #{subject.id}") @@ -23,7 +23,7 @@ namespace :subjects do str += ("(#{subject.id}, #{study_count}, #{course_study_count}, #{initiative_study}, " + "#{data.passed_count}, #{data.course_used_count}, #{data.school_used_count}, " + "'#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')") - puts "buffer_size: #{buffer_size}; subject_id: #{subject.id}; s: #{s.last}; subject: #{subject == s.last};" + puts "index: #{index}; worker_number: #{Parallel.worker_number}" puts "####str: #{str}" if buffer_size == 1000 || subject == s.last sql = "REPLACE INTO subject_records(#{column_value}) VALUES #{str}"