LG 8441 Prioritize ready enrollments#8488
Conversation
…-prioritize-ready-enrollments
…om:18F/identity-idp into jryan/lg-8441-prioritize-ready-enrollments
…ck enrollments that are ready
app/models/in_person_enrollment.rb
Outdated
| def self.needs_status_check_on_waiting_enrollments(check_interval) | ||
| where(ready_for_status_check: false). | ||
| and( | ||
| where(status: :pending), |
There was a problem hiding this comment.
These two methods have same body. Is the second one status should be :waiting?
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
@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 | ||
|
|
There was a problem hiding this comment.
Same here just method name is different?
There was a problem hiding this comment.
Got it, only difference is a flag.
| @@ -0,0 +1,83 @@ | |||
| module JobHelpers | |||
| module UspsProofingResultsJob | |||
| module AnalyticsHelper | |||
There was a problem hiding this comment.
We should consider passing this in as an instance instead of including it as a mixin.
There was a problem hiding this comment.
@NavaTim I'm curious, why do you think that's the better approach?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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.
| 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) |
There was a problem hiding this comment.
The comment on the new code doesn't cohesively combine the previous comments giving context on these errors.
There was a problem hiding this comment.
Generally speaking I feel we are using our entity models(ApplicationRecord/ActiveRecord) as service/query object, just different ways in different language.
NavaTim
left a comment
There was a problem hiding this comment.
Overall looks good, but I want to confirm the reason for the change in metric rounding before approving.
🎫 Ticket
Note: this ticket follows work @NavaTim completed in LG-8440. Pull Request here.
🛠 Summary of changes
📜 Testing Plan
To test locally:
truein your local devapplication.ymlfileGetUspsReadyProofingResultsJobandGetUspsWaitingProofingResultsJobare performed in theworkers.logfile located atlog/workers.log