Deprecate queuing PD application mailers and send all right away - #51411
Conversation
|
Thank you Meg for driving for this change! Excited to see us making this system better for us and the users |
|
+1 Meg, very exciting to see this simplification! pre-review question: do we send nag mail for incomplete applications, and how does that fit into the picture here? I thought maybe we did, but all I am seeing at first glance is that we show a banner on the homepage if they have an incomplete application. |
What does "nag mail" mean? For incomplete applications, we only send reminders to send in their applications. That logic happens in CompleteApplicationReminder UPDATE: oh "nag" like we're nagging them? I think that's the CompleteApplicationReminder –– happens with a cron job and sends one reminder at 7 days without an update and a second reminder at 14 days without an update |
haha, sorry for the made up nickname. yes |
davidsbailey
left a comment
There was a problem hiding this comment.
awesome work Meg! Good for users, good for engineers 🤝
|
|
||
| email.send! if deliver_now | ||
| email.send! | ||
| email.save! |
There was a problem hiding this comment.
do we still need to save? it looks like send! will take care of it via update!: https://github.com/code-dot-org/code-dot-org/blob/2650e3e42b51d0635b1b9b2f2d2d324887b03cca/dashboard/app/models/pd/application/email.rb
my recommendation would be to try removing email.save! and see if that passes drone. this can be optional or done in a later PR, though!
There was a problem hiding this comment.
Removing the save works, as expected!
|
|
||
| put :create, params: @test_params | ||
| application = TEACHER_APPLICATION_CLASS.last | ||
| assert_equal 1, application.emails.where.not(sent_at: nil).where(email_type: 'confirmation').count |
There was a problem hiding this comment.
this could be hard to debug if the create fails. I would suggest leaving the assert_response :success right after the put, here and below
|
|
||
| setup_all do | ||
| Pd::Application::ApplicationBase.any_instance.stubs(:deliver_email) | ||
| end |
There was a problem hiding this comment.
do you have an understanding of what happens to this stub after this test case runs (and finishes) later in this file?
for example, when that test case finishes, do we go back to actually calling deliver_email in subsequent test cases, or does the original stub from setup_all get restored?
I'm not sure I could say for sure from looking at it. one idea (as an alternative to investigating) would be to use setup instead of setup_all here.
There was a problem hiding this comment.
Oh great question –– I'll investigate
There was a problem hiding this comment.
I looked into trying to do an expect of a method that runs before the deliver_email stub, but nothing really made sense. So I went ahead and change the setup_all to setup as you recommended
As part of the refactor to clean up cron jobs 0a78244, the cron job was running
Pd::Application::Email.send_all_queued_emails. That line was removed, as the earlier parts of the cron job were no longer queuing emails, but rather sending them right away.This change introduced a bug (thread) in which queued emails from other parts of our system –– namely the decision emails –– were not being sent at all. I put the line back in in this PR #51201.
At this point, only one type of email –– the decision email –– does not get sent right away:
code-dot-org/dashboard/app/models/pd/application/teacher_application.rb
Line 389 in de87cfc
Since that's the only place that is not using the
deliver_now: trueparam, I got confirmation that these emails can also be sent right away.This PR does the following:
deliver_nowis no longer a param, but rather the only option. All emails will get sent right away for PD applications.acceptedanddeclined) from the model to the controller to avoid callbacks interfering with each other. These unit tests moved from the model test to the controller test, and certain other tests needed to change to trigger sending the email since.update(status: accepted)no longer sends the email.Links
Testing story
Deployment strategy
Follow-up work
Privacy
Security
Caching
PR Checklist: