Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions app/services/gpo_reminder_sender.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
class GpoReminderSender
LOCAL_DATABASE_TIMEOUT = 60_000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like the kind of thing better suited to be a config value than a constant, IMO, because the size of the tables, etc changes over time and having to do a code deploy to change that is not optimal


def send_emails(for_letters_sent_before)
letter_eligible_range =
IdentityConfig.store.usps_confirmation_max_days.days.ago..for_letters_sent_before

profiles_due_for_reminder = Profile.joins(:gpo_confirmation_codes).
where(
gpo_verification_pending_at: letter_eligible_range,
gpo_confirmation_codes: { reminder_sent_at: nil },
deactivation_reason: [nil, :in_person_verification_pending],
)

profiles_due_for_reminder.each do |profile|
profiles_due_for_reminder(letter_eligible_range).each do |profile|
profile.user.send_email_to_all_addresses(:gpo_reminder)
profile.gpo_confirmation_codes.first.update(reminder_sent_at: Time.zone.now)
analytics.idv_gpo_reminder_email_sent(user_id: profile.user.uuid)
Expand All @@ -19,6 +14,21 @@ def send_emails(for_letters_sent_before)

private

def profiles_due_for_reminder(letter_eligible_range)
ActiveRecord::Base.transaction do
ActiveRecord::Base.connection.execute(
"SET LOCAL statement_timeout = #{LOCAL_DATABASE_TIMEOUT}",
)

Profile.joins(:gpo_confirmation_codes).
where(
gpo_verification_pending_at: letter_eligible_range,
gpo_confirmation_codes: { reminder_sent_at: nil },
deactivation_reason: [nil, :in_person_verification_pending],
)
end
end

def analytics
Analytics.new(user: AnonymousUser.new, request: nil, session: {}, sp: nil)
end
Expand Down
6 changes: 6 additions & 0 deletions config/initializers/job_configurations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@
cron: cron_24h,
args: -> { [Time.zone.today] },
},
# Send reminder letters for old, outstanding GPO verification codes
send_gpo_code_reminders: {
class: 'GpoReminderJob',
cron: cron_24h,
args: -> { [14.days.ago] },
},
monthly_account_reuse_report: {
class: 'Reports::MonthlyAccountReuseReport',
cron: cron_1st_of_mo,
Expand Down