moving weekend logic into the next_attempt_at logic in recipient_schedule

This commit is contained in:
Jared Cosulich 2017-04-18 12:00:24 -04:00
parent ac7858c5f6
commit a2300a58b9
4 changed files with 32 additions and 12 deletions

View file

@ -60,12 +60,18 @@ class RecipientSchedule < ApplicationRecord
attempted_question_ids: attempted.empty? ? nil : attempted.join(','),
queued_question_ids: queued.empty? ? nil : queued.join(','),
last_attempt_at: (unanswered_attempt || attempt).sent_at,
next_attempt_at: next_attempt_at + (60 * 60 * schedule.frequency_hours)
next_attempt_at: next_valid_attempt_time
)
end
return (unanswered_attempt || attempt)
end
def next_valid_attempt_time
local_time = (next_attempt_at + (60 * 60 * schedule.frequency_hours)).in_time_zone('Eastern Time (US & Canada)')
local_time += 1.day while local_time.on_weekend?
return local_time
end
def self.create_for_recipient(recipient_or_recipient_id, schedule, next_attempt_at=nil)
if next_attempt_at.nil?
next_attempt_at = Time.at(schedule.start_date.to_time.to_i + (60 * schedule.time))