Hookup gear reminder emails

This commit is contained in:
Seth Call 2025-06-14 00:33:03 -05:00
parent e7923dca9b
commit 7c9e449c4b
4 changed files with 36 additions and 8 deletions

View File

@ -122,6 +122,7 @@ require "jam_ruby/lib/email_new_musician_match"
require "jam_ruby/lib/musician_filter"
require "jam_ruby/lib/email_profile_reminder"
require "jam_ruby/lib/email_signup_survey"
require "jam_ruby/lib/gear_setup_reminder"
require "jam_ruby/amqp/amqp_connection_manager"
require "jam_ruby/database"
require "jam_ruby/message_factory"

View File

@ -16,7 +16,7 @@ module JamRuby
end
def self.survey_users
cutoff_date = Date.parse(Rails.application.config.signup_survey_cutoff_date) # Define a cutoff date for the survey
cutoff_date = Date.parse(Rails.application.config.signup_survey_cutoff_date) # Define a cutoff date for the survey/gear setup emails
User.where("users.signup_survey_sent_at IS NULL AND users.created_at < ? AND users.created_at > ?", 1.days.ago, cutoff_date)
end
end

View File

@ -1,20 +1,46 @@
module JamRuby
class GearSetupReminder
@@log = Logging.logger[GearSetupReminder]
def self.send_reminders
begin
cutoff_date = Date.parse(Rails.application.config.signup_survey_cutoff_date) # Define a cutoff date for the survey/gear setup emails
reminder1_users(cutoff_date).find_each do |user|
UserMailer.gear_setup_reminder1(user).deliver_now
User.where(id: user.id).update_all(gear_setup_reminder1_sent_at: Time.now)
end
reminder2_users(cutoff_date).find_each do |user|
UserMailer.gear_setup_reminder2(user).deliver_now
User.where(id: user.id).update_all(gear_setup_reminder2_sent_at: Time.now)
end
reminder3_users(cutoff_date).find_each do |user|
UserMailer.gear_setup_reminder3(user).deliver_now
User.where(id: user.id).update_all(gear_setup_reminder3_sent_at: Time.now)
end
rescue Exception => e
@@log.error("unable to send gear setup reminder email #{e}")
puts "unable to send gear setup reminder email #{e}"
end
end
def self.prospect_users
User.where("users.first_certified_gear_at IS NULL")
end
def self.reminder1_users
GearSetupReminder.prospect_users.where("users.created_at > ? AND users.gear_setup_reminder1_sent_at IS NULL", 1.day.ago)
def self.reminder1_users(cutoff)
GearSetupReminder.prospect_users.where("users.created_at < ? AND users.created_at > ? AND users.gear_setup_reminder1_sent_at IS NULL", 1.day.ago, cutoff_date)
end
def self.reminder2_users
GearSetupReminder.prospect_users.where("users.created_at > ? AND users.gear_setup_reminder1_sent_at IS NOT NULL AND users.gear_setup_reminder2_sent_at IS NULL", 3.days.ago)
def self.reminder2_users(cutoff)
GearSetupReminder.prospect_users.where("users.created_at < ? AND users.created_at > ? AND users.gear_setup_reminder1_sent_at IS NOT NULL AND users.gear_setup_reminder2_sent_at IS NULL", 3.days.ago, cutoff_date)
end
def self.reminder3_users
GearSetupReminder.prospect_users.where("users.created_at > ? AND users.gear_setup_reminder2_sent_at IS NOT NULL AND users.gear_setup_reminder3_sent_at IS NULL", 5.days.ago)
def self.reminder3_users(cutoff)
GearSetupReminder.prospect_users.where("users.created_at < ? AND users.created_at > ? AND users.gear_setup_reminder2_sent_at IS NOT NULL AND users.gear_setup_reminder3_sent_at IS NULL", 5.days.ago, cutoff_date)
end
end

View File

@ -18,6 +18,7 @@ module JamRuby
#EmailProfileReminder.send_reminders
EmailSignupSurvey.send_survey
GearSetupReminder.send_reminders
ConnectionManager.new.cleanup_dangling
@@log.info("done")