Skip to content

LG 8441 Prioritize ready enrollments#8488

Merged
JackRyan1989 merged 34 commits intomainfrom
jryan/lg-8441-prioritize-ready-enrollments
Jun 5, 2023
Merged

LG 8441 Prioritize ready enrollments#8488
JackRyan1989 merged 34 commits intomainfrom
jryan/lg-8441-prioritize-ready-enrollments

Conversation

@JackRyan1989
Copy link
Contributor

@JackRyan1989 JackRyan1989 commented May 25, 2023

🎫 Ticket

Note: this ticket follows work @NavaTim completed in LG-8440. Pull Request here.

🛠 Summary of changes

  1. Created two new sub-classes of GetUspsProofingResultsJob
  2. Each subclass is set to be called at different frequencies via cron
  3. Each subclass processes different enrollments: enrollments that have been marked 'ready' by our SQS job, and those not marked 'ready'.
  4. Tests have been created for each subclass
  5. Refactored GetUspsProofingResultsJob
  6. Pulled config checks into separate methods
  7. Turned percent error calculation into own method
  8. Moved email related methods into new module
  9. Moved analytics related methods into new module
  10. Created wrapper methods for each analytics method
  11. Removed an error handler method with duplicate internals to other error handler method

📜 Testing Plan

To test locally:

  • Set the following config values to true in your local dev application.yml file
  • in_person_proofing_enabled
  • in_person_enrollments_ready_job_enabled
  • Check that the GetUspsReadyProofingResultsJob and GetUspsWaitingProofingResultsJob are performed in the workers.log file located at log/workers.log

@JackRyan1989 JackRyan1989 requested review from a team and tomas-nava May 25, 2023 20:30
@JackRyan1989 JackRyan1989 self-assigned this May 25, 2023
def self.needs_status_check_on_waiting_enrollments(check_interval)
where(ready_for_status_check: false).
and(
where(status: :pending),
Copy link
Contributor

Choose a reason for hiding this comment

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

These two methods have same body. Is the second one status should be :waiting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dawei-nava No actually. These two methods are very subtly different. The first where check is the only difference. needs_status_check_on_waiting_enrollments should check for enrollments that are not ready for status check, whereas needs_status_check_on_ready_enrollments checks for enrollments that are ready for a status check.

They are still both pending enrollments, as the user has not yet visited the Post Office and they haven't been expired after the 30 day cutoff yet.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, i did not notice the ready_for_status_check differences. So if the only difference is ready_for_status_check true of false, just like @NavaTim said, at least these two methods may at least get consolidated into one with boolean as second parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dawei-nava Yes, I'm going to follow @NavaTim's suggestion. I think that'll hopefully reduce any potential confusion.

check_interval.cover?(status_check_attempted_at)
)
end

Copy link
Contributor

Choose a reason for hiding this comment

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

Same here just method name is different?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dawei-nava see my answer above.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it, only difference is a flag.

@JackRyan1989 JackRyan1989 changed the title LG 8441 prioritize ready enrollments - [WIP] LG 8441 prioritize ready enrollments May 30, 2023
@JackRyan1989 JackRyan1989 marked this pull request as ready for review May 30, 2023 16:17
@JackRyan1989 JackRyan1989 requested a review from a team May 30, 2023 16:17
@@ -0,0 +1,83 @@
module JobHelpers
module UspsProofingResultsJob
module AnalyticsHelper
Copy link
Contributor

Choose a reason for hiding this comment

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

We should consider passing this in as an instance instead of including it as a mixin.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@NavaTim I'm curious, why do you think that's the better approach?

Copy link
Contributor

Choose a reason for hiding this comment

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

Passing it in as an object makes it easier to test and enforce a contract. That in turn can help increase the confidence that we're not breaking anything when we update either the analytics or the job logic, and the complexity introduced by inheritance is removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So @NavaTim I'm running into an issue where fake_analytics.rb is not aware of the analytics calls I'm making from this helper class. I'm not sure if I'm going to need to make a new Fake_Analytics class to be aware of these methods or not. If I need to refactor Fake_analytics.rb to make this change work, I might be inclined to shelve this refactor until a later time and fully separate the work. I think scope creep is starting to become an issue here for me.

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like you're making the classes stateful, but it's better to keep them stateless, esp. in a process like this job where many different records are processed that differ in that type of state. I would suggest completely hiding the fact that a new Analytics instance may be constructed inside AnalyticsHelper by taking the User object as a parameter for each of the methods (as you had in the module version).

I expect this will require some changes to tests since all of this logic was previously encapsulated in the job. I would suggest initially going about this by treating the original test as an integration rather than unit test & making sure that it passes with real (not mock) instances of the new classes until after you've completed the refactor.

All that said - I don't think this type of change is a prerequisite for merging the code. It's more important that the job can be configured (and by default is configured) as functionally identical to the original job, but can also be reconfigured to use the ready_for_status_check flag instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@NavaTim Yeah, I'm now spending more time on this refactor than the actual requirements of the ticket, so I think I'm going to abandon them for the time being and open a separate ticket.

Comment on lines 99 to 104
rescue Faraday::ClientError, Faraday::ServerError, Faraday::Error => err
# 4xx or 5xx status code.
# These are unexpected but will have some sort of response body that we can try to log data from
# Faraday Timeouts, failed connections, parsing errors, and other HTTP errors.
# These generally won't have a response body
handle_client_or_server_error(err, enrollment)
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment on the new code doesn't cohesively combine the previous comments giving context on these errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

WIll fix.

Copy link
Contributor

Choose a reason for hiding this comment

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

Generally speaking I feel we are using our entity models(ApplicationRecord/ActiveRecord) as service/query object, just different ways in different language.

@JackRyan1989 JackRyan1989 requested a review from a team June 5, 2023 18:15
@JackRyan1989 JackRyan1989 changed the title LG 8441 prioritize ready enrollments LG 8441 Prioritize ready enrollments Jun 5, 2023
Copy link
Contributor

@NavaTim NavaTim left a comment

Choose a reason for hiding this comment

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

Overall looks good, but I want to confirm the reason for the change in metric rounding before approving.

@JackRyan1989 JackRyan1989 merged commit b73775d into main Jun 5, 2023
@JackRyan1989 JackRyan1989 deleted the jryan/lg-8441-prioritize-ready-enrollments branch June 5, 2023 20:59
@solipet solipet mentioned this pull request Jun 6, 2023
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