Class: CourseEnrollmentWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Job
Defined in:
app/workers/course_enrollment_worker.rb

Instance Method Summary collapse

Instance Method Details

#performObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/workers/course_enrollment_worker.rb', line 6

def perform
  #Send 4 reminders, every 30 days, when there is no progress in a course for 30 days
  CourseEnrollment.active.each do |ce|
    last_updated_at = ce.customer_topics.maximum(:updated_at)

    #If there is any progress in the last 30 days, reset the reminders
    if last_updated_at > 30.days.ago
      #We use update_columns so it doesnt' update the updated_at field
      ce.update_columns(reminder_1: nil, reminder_2: nil, reminder_3: nil, reminder_4: nil)
    else
      #Otherwise, send a reminder depending on when was the last time we sent another reminder
      if last_updated_at < 30.days.ago && ce.reminder_1.nil?
        ce.send_progress_reminder(30)
      end

      [60,90,120].each_with_index do |days, index|
          if last_updated_at < days.days.ago &&
                 ce.send("reminder_#{index+2}").nil? &&
                 ce.send("reminder_#{index+1}").present? &&
                 ce.send("reminder_#{index+1}") < 30.days.ago #make sure we don't send another reminder within 30 days of the previous one
            ce.send_progress_reminder(days)
            break
          end
        end

    end

  end
end