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_subject_course_stude...

23 lines
842 B

5 years ago
class CreateSubjectCourseStudentJob < ApplicationJob
queue_as :default
def perform(course_id)
course = Course.find_by(id: course_id)
return if course.blank? || course.subject.blank?
attrs = %i[course_id user_id role created_at updated_at]
same_attrs = {course_id: course.id, role: 4}
Rails.logger.info("1:course.students.count:##{course.students.count}")
5 years ago
CourseMember.bulk_insert(*attrs) do |worker|
course.subject.subject_appointments.each do |app|
Rails.logger.info("##{course.students.where(user_id: app.user_id)}")
5 years ago
next if course.students.where(user_id: app.user_id).any?
5 years ago
worker.add same_attrs.merge(user_id: app.user_id)
end
end
5 years ago
Rails.logger.info("2:course.students.count:##{course.students.count}")
course.subject.subject_appointments.destroy_all
5 years ago
end
end