You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/app/jobs/statistic_studentwork_job.rb

19 lines
707 B

class StatisticStudentworkJob < ApplicationJob
queue_as :default
def perform(*args)
School.find_in_batches(batch_size: 50) do |school|
Parallel.each_with_index(school, in_processes: 5) do |s|
student_work = StudentWork.find_by_sql("SELECT count(*) AS count
FROM student_works
JOIN user_extensions AS u ON u.user_id = student_works.user_id AND u.school_id = #{s.id}")
report = SchoolReport.find_or_initialize_by(school_id: s.id)
report.school_name = s.name
report.student_work_count = student_work.first['count']
report.save
end
end
end
end