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.
24 lines
668 B
24 lines
668 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|
|
|
unless StudentWork.where(user_id: user_id, homework_common_id: homework.id).exists?
|
|
worker.add same_attrs.merge(user_id: user_id)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|