Updated both background jobs to not break HourlyJob

This commit is contained in:
Seth Call 2025-06-14 00:22:02 -05:00
parent 55372bf83d
commit e7923dca9b
7 changed files with 58 additions and 23 deletions

View File

@ -16,3 +16,11 @@
execute "ALTER TABLE users DROP COLUMN profile_complete_reminder3_sent_at"
end
end
=begin
ALTER TABLE users ADD COLUMN profile_completed_at TIMESTAMP
CREATE INDEX index_users_on_profile_completed_at ON users USING btree (profile_completed_at)
ALTER TABLE users ADD COLUMN profile_complete_reminder1_sent_at TIMESTAMP
ALTER TABLE users ADD COLUMN profile_complete_reminder2_sent_at TIMESTAMP
ALTER TABLE users ADD COLUMN profile_complete_reminder3_sent_at TIMESTAMP
UPDATE users set profile_completed_at=NOW() WHERE users.id IN (SELECT player_id FROM musicians_instruments) OR users.id IN (SELECT player_id FROM genre_players);
end

View File

@ -11,3 +11,10 @@
execute "ALTER TABLE users DROP COLUMN gear_setup_reminder3_sent_at"
end
end
=begin
ALTER TABLE users ADD COLUMN gear_setup_reminder1_sent_at TIMESTAMP;
ALTER TABLE users ADD COLUMN gear_setup_reminder2_sent_at TIMESTAMP;
ALTER TABLE users ADD COLUMN gear_setup_reminder3_sent_at TIMESTAMP;
end

View File

@ -6,3 +6,6 @@
execute "ALTER TABLE users DROP COLUMN signup_survey_sent_at"
end
end
=begin
ALTER TABLE users ADD COLUMN signup_survey_sent_at TIMESTAMP
=end

View File

@ -120,6 +120,8 @@ require "jam_ruby/lib/subscription_message"
require "jam_ruby/lib/stats.rb"
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/amqp/amqp_connection_manager"
require "jam_ruby/database"
require "jam_ruby/message_factory"

View File

@ -1,25 +1,30 @@
module JamRuby
class EmailProfileReminder
@@log = Logging.logger[EmailProfileReminder]
def self.send_reminders
#If the user has not updated their profile 1 day after signup, then send reminder email1
reminder1_users.each do |user|
UserMailer.profile_complete_reminder1(user).deliver_now
user.update(profile_complete_reminder1_sent_at: Time.now)
end
begin
#If the user has not updated their profile 1 day after signup, then send reminder email1
reminder1_users.find_each do |user|
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.each do |user|
UserMailer.profile_complete_reminder2(user).deliver_now
user.update(profile_complete_reminder2_sent_at: Time.now)
end
#If the user has not updated their profile 3 days after signup, then send reminder email2
reminder2_users.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.each do |user|
UserMailer.profile_complete_reminder3(user).deliver_now
user.update(profile_complete_reminder3_sent_at: Time.now)
#If the user has not updated their profile 5 days after signup, then send reminder email3
reminder3_users.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
@ -27,15 +32,15 @@ module JamRuby
end
def self.reminder1_users
EmailProfileReminder.prospect_users.where("users.created_at > ? AND users.profile_complete_reminder1_sent_at IS NULL", 1.day.ago)
EmailProfileReminder.prospect_users.where("users.created_at < ? AND users.profile_complete_reminder1_sent_at IS NULL", 1.day.ago)
end
def self.reminder2_users
EmailProfileReminder.prospect_users.where("users.created_at > ? AND users.profile_complete_reminder1_sent_at IS NOT NULL AND users.profile_complete_reminder2_sent_at IS NULL", 3.days.ago)
EmailProfileReminder.prospect_users.where("users.created_at < ? AND users.profile_complete_reminder1_sent_at IS NOT NULL AND users.profile_complete_reminder2_sent_at IS NULL", 3.days.ago)
end
def self.reminder3_users
EmailProfileReminder.prospect_users.where("users.created_at > ? AND users.profile_complete_reminder2_sent_at IS NOT NULL AND users.profile_complete_reminder3_sent_at IS NULL", 5.days.ago)
EmailProfileReminder.prospect_users.where("users.created_at < ? AND users.profile_complete_reminder2_sent_at IS NOT NULL AND users.profile_complete_reminder3_sent_at IS NULL", 5.days.ago)
end

View File

@ -1,10 +1,17 @@
module JamRuby
class EmailSignupSurvey
@@log = Logging.logger[EmailSignupSurvey]
def self.send_survey
# if signup survey email has not been sent to this user, then send it
survey_users.each do |user|
UserMailer.signup_survey(user).deliver_now
user.update(signup_survey_sent_at: Time.now)
begin
# if signup survey email has not been sent to this user, then send it
survey_users.find_each do |user|
UserMailer.signup_survey(user).deliver_now
User.where(id: user.id).update_all(signup_survey_sent_at: Time.now)
end
rescue Exception => e
@@log.error("unable to send surevy email e=#{e}")
puts "unable to send surevy email e=#{e}"
end
end

View File

@ -13,7 +13,10 @@ module JamRuby
#TeacherPayment.hourly_check
User.hourly_check
AffiliatePartner.tally_up(Date.today)
EmailProfileReminder.send_reminders
# bring me back in once tested profile_completed_at is set somewhere
#EmailProfileReminder.send_reminders
EmailSignupSurvey.send_survey
ConnectionManager.new.cleanup_dangling