Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LG-11520: Add job to expire old GPO pending profiles #9545

Merged
merged 17 commits into from
Nov 9, 2023

Conversation

matthinz
Copy link
Member

@matthinz matthinz commented Nov 3, 2023

🎫 Ticket

LG-11520

🛠 Summary of changes

Adds a new job, GpoExpirationJob, that looks for GPO profiles that are no longer usable and marks them as "expired". The job is meant to eventually run daily, but is not currently set to run automatically (that will be in a subsequent PR).

An expired GPO profile:

  • Does not have any valid GPO codes associated with it
  • Was created > 30 days ago (so the user can't request a new code)

To mark a Profile expired, we clear the gpo_pending_verification_at column and set the gpo_verification_expired_at to the current date/time.

(Note: This work was broken off from #9475 and does not include any email notifications.)

Update as of 11/8 The deployment plan here is to migrate the bulk of existing profiles via a rollplan (working on the doc for that now) using the rake task this PR includes

📜 Testing Plan

  • Begin IdV, taking the GPO route and requesting a letter.
  • Once you have your GPO code, get in your time machine and move forward 15 days
  • Use the Rails console to run the job: GpoExpirationJob.new.perform
  • Verify your profile is not automatically expired
  • Request another GPO code
  • Once you have your GPO code, get in your time machine and move forward another 16 days (You should now be 31 days after your first request for a letter)
  • Use the Rails console to run the job: GpoExpirationJob.new.perform
  • Verify that your profile is not expired (since you still have an active code)
  • Use your time machine to move forward another 15 days
  • Use the Rails console to run the job: GpoExpirationJob.new.perform
  • Verify your profile is now expired (gpo_verification_expired_at is set)
  • Use the Rails console to run the job one last time: GpoExpirationJob.new.perform
  • Verify no additional changes are made and no more profiles are expired by the second run

To test this without a time machine, you will first want to allow yourself to repeatedly request new GPO letters by updating your application.yml:

  # Allow re-requesting GPO letters same-day
  minimum_wait_before_another_usps_letter_in_hours: 0

Then, in the Rails console:

# Clear out any codes & GPO profiles you have sitting in your local db to reset to a baseline state
GpoConfirmationCode.delete_all
Profile.update_all(gpo_verification_pending_at: nil)

# STOP. Go to the IDP and request a letter

# Grab the code you requested and its profile
first_code = GpoConfirmationCode.order(code_sent_at: :desc).first
profile = first_code.profile

# Simulate 15 days passing
profile.update(created_at: 15.days.ago)
first_code.update(code_sent_at: 15.days.ago)

# Run the job (this should not expire any profiles)
GpoExpirationJob.new.perform

# STOP. Go request another letter, then come back here and grab your new code
second_code = GpoConfirmationCode.order(code_sent_at: :desc).first

# Simulate 16 more days passing
# (first_code is now expired, but second_code is still active)
profile.update(created_at: 31.days.ago)
first_code.update(code_sent_at: 31.days.ago)
second_code.update(code_sent_at: 16.days.ago)

# Run the job (should not expire anything, since second_code is still active)
GpoExpirationJob.new.perform

# Simulate 14 more days passing (second_code is now expired)
profile.update(created_at: 45.days.ago)
first_code.update(code_sent_at: 45.days.ago)
second_code.update(code_sent_at: 30.days.ago)

# Run the job (should expire the profile and log an idv_gpo_expired event)
GpoExpirationJob.new.perform

# Verify profile was expired
profile.reload
profile.gpo_verification_pending_at # Should be nil
profile.gpo_verification_expired_at # Should be set to current time

# Run the job AGAIN and verify no additional profiles are expired
GpoExpirationJob.new.perform

@matthinz matthinz force-pushed the matthinz/gpo-expiration branch from e8b32e1 to 08a9e9d Compare November 6, 2023 20:07
@matthinz matthinz marked this pull request as ready for review November 6, 2023 22:47
@matthinz matthinz requested a review from a team November 6, 2023 22:47
app/models/profile.rb Show resolved Hide resolved
app/services/analytics_events.rb Outdated Show resolved Hide resolved
db/schema.rb Show resolved Hide resolved
spec/jobs/gpo_expiration_job_spec.rb Outdated Show resolved Hide resolved
This column was in place locally for me after working on my old branch.
Copy link
Contributor

@solipet solipet left a comment

Choose a reason for hiding this comment

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

A couple minor comments, otherwise looks good to me.

Ran through the manual test procedure and it worked as expected.

app/jobs/gpo_expiration_job.rb Outdated Show resolved Hide resolved
app/jobs/gpo_expiration_job.rb Show resolved Hide resolved
app/services/analytics_events.rb Outdated Show resolved Hide resolved
Track when the user originally entered the GPO flow on the expiration analytics event.
Allow limiting scope to profiles older than a certain age.
Includes rollback functionality.
app/jobs/gpo_expiration_job.rb Outdated Show resolved Hide resolved
lib/tasks/backfill_gpo_expiration.rake Show resolved Hide resolved
spec/factories/users.rb Show resolved Hide resolved
@theabrad
Copy link
Contributor

theabrad commented Nov 8, 2023

You will want to add this job to config/initializers/job_configurations.rb so that it can run daily.

@matthinz
Copy link
Member Author

matthinz commented Nov 8, 2023

You will want to add this job to config/initializers/job_configurations.rb so that it can run daily.

Current plan is to do that in a separate PR so that we can expire the bulk of the existing profiles via rollplan first.

@matthinz matthinz merged commit 54bd7f9 into main Nov 9, 2023
2 checks passed
@matthinz matthinz deleted the matthinz/gpo-expiration branch November 9, 2023 00:27
matthinz added a commit that referenced this pull request Nov 13, 2023
Accidentally committed this as part of #9545

[skip changelog]
matthinz added a commit that referenced this pull request Nov 13, 2023
Accidentally committed this as part of #9545

[skip changelog]
zachmargolis pushed a commit that referenced this pull request Nov 13, 2023
Accidentally committed this as part of #9545

[skip changelog]

(cherry picked from commit 15f9b25)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants