52 lines
2.8 KiB
Ruby
52 lines
2.8 KiB
Ruby
module JamRuby
|
|
class EmailProfileReminder
|
|
@@log = Logging.logger[EmailProfileReminder]
|
|
|
|
def self.send_reminders
|
|
begin
|
|
cutoff_date = Date.parse(Rails.application.config.profile_complete_reminders_effective_from_date) # Define a cutoff date for the profile completion emails
|
|
#If the user has not updated their profile 1 day after signup, then send reminder email1
|
|
reminder1_users(cutoff_date).find_each do |user|
|
|
puts "reminder1_users user: #{user.id}"
|
|
UserMailer.profile_complete_reminder1(user).deliver_now
|
|
User.where(id: user.id).update_all(profile_complete_reminder1_sent_at: Time.now)
|
|
end
|
|
|
|
#If the user has not updated their profile 3 days after signup, then send reminder email2
|
|
reminder2_users(cutoff_date).find_each do |user|
|
|
UserMailer.profile_complete_reminder2(user).deliver_now
|
|
User.where(id: user.id).update_all(profile_complete_reminder2_sent_at: Time.now)
|
|
end
|
|
|
|
#If the user has not updated their profile 5 days after signup, then send reminder email3
|
|
reminder3_users(cutoff_date).find_each do |user|
|
|
UserMailer.profile_complete_reminder3(user).deliver_now
|
|
User.where(id: user.id).update_all(profile_complete_reminder3_sent_at: Time.now)
|
|
end
|
|
rescue Exception => e
|
|
@@log.error("unable to send profile reminder email=#{e}")
|
|
puts "unable to send profile reminder email=#{e}"
|
|
end
|
|
end
|
|
|
|
def self.prospect_users
|
|
User.where("users.profile_completed_at IS NULL AND users.subscribe_email = ?", true)
|
|
end
|
|
|
|
def self.reminder1_users(cutoff_date)
|
|
# ensure that the user has had the account for at least one day
|
|
puts "reminder1_users cutoff_date: #{cutoff_date}"
|
|
EmailProfileReminder.prospect_users.where("users.created_at > ? AND users.profile_complete_reminder1_sent_at IS NULL AND (NOW() - users.created_at) > INTERVAL '1 day'", cutoff_date)
|
|
end
|
|
|
|
def self.reminder2_users(cutoff_date)
|
|
# ensure that the user has had the account for at least three days and guard against rapid back-to-back emails
|
|
EmailProfileReminder.prospect_users.where("users.created_at > ? AND users.profile_complete_reminder1_sent_at < ? AND users.profile_complete_reminder1_sent_at IS NOT NULL AND users.profile_complete_reminder2_sent_at IS NULL", cutoff_date, 2.days.ago)
|
|
end
|
|
|
|
def self.reminder3_users(cutoff_date)
|
|
# ensure that user has had the profile for 5 days and guard against rapid back-to-back emails
|
|
EmailProfileReminder.prospect_users.where("users.created_at > ? AND users.profile_complete_reminder2_sent_at < ? AND users.profile_complete_reminder2_sent_at IS NOT NULL AND users.profile_complete_reminder3_sent_at IS NULL", cutoff_date, 2.days.ago)
|
|
end
|
|
end
|
|
end |