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/create_student_work_job.rb

22 lines
562 B

class CreateStudentWorkJob < ApplicationJob
queue_as :default
def perform(homework_id)
homework = HomeworkCommon.find_by(id: homework_id)
course = homework&.course
return if homework.blank? || course.blank?
attrs = %i[homework_common_id user_id created_at updated_at]
same_attrs = {homework_common_id: homework.id}
StudentWork.bulk_insert(*attrs) do |worker|
student_ids = course.students.pluck(:user_id)
student_ids.each do |user_id|
worker.add same_attrs.merge(user_id: user_id)
end
end
end
end