Skip to content
This repository has been archived by the owner on Sep 25, 2019. It is now read-only.

Commit

Permalink
Do not create pending actions for the submitted students
Browse files Browse the repository at this point in the history
  • Loading branch information
allenwq committed Jan 16, 2016
1 parent 95f7cf8 commit 9bf89aa
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions app/jobs/background_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def perform

case name
when :pending_action
create_pending_actions(course, item_type, item_id)
create_pending_actions(course, item)
when :mission_due
mission_reminder(course, item)
when :notification
Expand All @@ -33,15 +33,22 @@ def perform
end
end

def create_pending_actions(course, item_type, item_id)
course.user_courses.student.each do |sc|
exist = sc.pending_actions.where(item_type: item_type, item_id: item_id).first
next if exist
pa = sc.pending_actions.build
pa.course = course
pa.item_type = item_type
pa.item_id = item_id
pa.save
def create_pending_actions(course, item)
students = course.user_courses.student
if item.is_a?(Assessment)
submitted_students = item.submissions.submitted_or_graded.includes(:std_course).map(&:std_course)
students -= submitted_students
end

students.each do |student|
exists = student.pending_actions.where(item_type: item.class.name, item_id: item.id)
next if exists.any?

pending_action = student.pending_actions.build
pending_action.course = course
pending_action.item_type = item_type
pending_action.item_id = item_id
pending_action.save
end
end

Expand Down

0 comments on commit 9bf89aa

Please sign in to comment.