diff --git a/lib/tasks/statistic_subject_info.rake b/lib/tasks/statistic_subject_info.rake index 50980c2e8..8c3c02fb2 100644 --- a/lib/tasks/statistic_subject_info.rake +++ b/lib/tasks/statistic_subject_info.rake @@ -10,7 +10,7 @@ namespace :subjects do column_value = "subject_id, study_count, course_study_count, initiative_study, passed_count, course_used_count, " + "school_used_count, created_at, updated_at" subjects.find_in_batches(batch_size: 50) do |s| - Parallel.each_with_index(s, in_threads: 4) do |subject, index| + Parallel.each_with_index(s, in_processes: 4) do |subject, index| puts("---------------------data_statistic: #{subject.id}") Rails.logger.info("---------------------data_statistic: #{subject.id}") data = Subjects::DataStatisticService.new(subject) @@ -23,7 +23,8 @@ namespace :subjects do "#{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')}')") buffer_size += 1 - if buffer_size == 1000 || subjects.count == (index+1) + puts "buffer_size: #{buffer_size}; subjects_count: #{s.count}; index:#{index+1}" + if buffer_size == 1000 || s.count == (index+1) sql = "REPLACE INTO subject_records(#{column_value}) VALUES #{str}" puts sql ActiveRecord::Base.connection.execute sql @@ -51,7 +52,7 @@ namespace :subjects do "choice_shixun_frequency, created_at, updated_at" subjects.find_in_batches(batch_size: 50) do |s| - Parallel.each(s, in_threads: 4) do |subject| + Parallel.each(s, in_processes: 4) do |subject| puts("---------------------course_info_statistic: #{subject.id}") Rails.logger.info("---------------------course_info_statistic: #{subject.id}") data = Subjects::CourseUsedInfoService.call(subject) @@ -90,7 +91,7 @@ namespace :subjects do column_value = "subject_id, shixun_id, stage, shixun_name, challenge_count, course_count, " + "school_count, used_count, passed_count, evaluate_count, passed_ave_time, created_at, updated_at" subjects.find_in_batches(batch_size: 50) do |s| - Parallel.each_with_index(s, in_threads: 4) do |subject| + Parallel.each_with_index(s, in_processes: 4) do |subject| puts("---------------------shixun_info_statistic: #{subject.id}") Rails.logger.info("---------------------shixun_info_statistic: #{subject.id}") data = Subjects::ShixunUsedInfoService.call(subject) @@ -131,7 +132,7 @@ namespace :subjects do "code_line_count, evaluate_count, cost_time, created_at, updated_at" subjects.find_in_batches(batch_size: 50) do |s| - Parallel.each_with_index(s, in_threads: 4) do |subject, index| + Parallel.each_with_index(s, in_processes: 4) do |subject, index| puts("---------------------user_info_statistic: #{subject.id}") data = Subjects::UserUsedInfoService.call(subject) data.each do |key|