parent
1694ae7f48
commit
4a104921ba
@ -0,0 +1,21 @@
|
|||||||
|
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
|
@ -0,0 +1,5 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe CreateStudentWorkJob, type: :job do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
Loading…
Reference in new issue