Skip to content

Deprecate queuing PD application mailers and send all right away - #51411

Merged
megcrenshaw merged 20 commits into
stagingfrom
meg/deprecate-queuing-pd-application-mailers
Apr 24, 2023
Merged

Deprecate queuing PD application mailers and send all right away#51411
megcrenshaw merged 20 commits into
stagingfrom
meg/deprecate-queuing-pd-application-mailers

Conversation

@megcrenshaw

@megcrenshaw megcrenshaw commented Apr 19, 2023

Copy link
Copy Markdown

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:

queue_email(status) if should_send_decision_email?

Since that's the only place that is not using the deliver_now: true param, I got confirmation that these emails can also be sent right away.

This PR does the following:

  • Refactors the functionality so that deliver_now is no longer a param, but rather the only option. All emails will get sent right away for PD applications.
  • Now that all emails get sent right away, there is no email queue, so removes all references to "queuing" an email and "unsent" emails for PD Applications
  • Moves functionality to send "decision" emails (accepted and declined) 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:

  • Tests provide adequate coverage
  • Privacy and Security impacts have been assessed
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

@megcrenshaw megcrenshaw changed the title Meg/deprecate queuing pd application mailers Deprecate queuing PD application mailers and send all right away Apr 19, 2023
@megcrenshaw
megcrenshaw marked this pull request as ready for review April 20, 2023 12:29
@megcrenshaw
megcrenshaw requested a review from a team April 20, 2023 12:29
@dmcavoy

dmcavoy commented Apr 20, 2023

Copy link
Copy Markdown
Contributor

Thank you Meg for driving for this change! Excited to see us making this system better for us and the users

@davidsbailey

Copy link
Copy Markdown
Member

+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.

@megcrenshaw

megcrenshaw commented Apr 20, 2023

Copy link
Copy Markdown
Author

+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

@davidsbailey

Copy link
Copy Markdown
Member

+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 CompleteApplicationReminder is what I was looking for, thanks!

@davidsbailey davidsbailey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

awesome work Meg! Good for users, good for engineers 🤝


email.send! if deliver_now
email.send!
email.save!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ah nice –– will try that

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good call!


setup_all do
Pd::Application::ApplicationBase.any_instance.stubs(:deliver_email)
end

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

do you have an understanding of what happens to this stub after this test case runs (and finishes) later in this file?

application.expects(:deliver_email).once

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Oh great question –– I'll investigate

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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

@megcrenshaw
megcrenshaw merged commit d5fdceb into staging Apr 24, 2023
@megcrenshaw
megcrenshaw deleted the meg/deprecate-queuing-pd-application-mailers branch April 24, 2023 14:27
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.

3 participants