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
Add *_deliver callbacks for Action Mailer
#47630
Conversation
6770bf9
to
5d14b88
Compare
|
LGTM, but can you added documentation for this new feature? |
5d14b88
to
84c6737
Compare
*_deliver callbacks for Action Mailer
84c6737
to
93f3128
Compare
93f3128
to
468d806
Compare
|
✅ I added documentation and changelog. I also changed the callback name from |
|
@bensheldon Hi, nice addition. |
|
@Bhacaz thanks for the question! I wouldn't say "obsolete" because the Mail gem is usable outside of Rails, so interceptors/observers are still necessary from Mail's perspective. From the perspective of Rails, I think interceptors/observers are less necessary. I'm not confident to say un-necessary. I mentioned the use-cases that I find myself frequently writing (updating a record at delivery, getting a provider id, responding to delivery errors), but there are likely uses that I'm unaware of. From looking at the documentation, I could imagine that a more significant documentation change might be:
|
|
@bensheldon, Thanks for the fantastic feature.
To verify the above sentence, I ran a single test of Expected order of callbacks -
To get this expected order of callbacks, many more significant changes would be required to the |
|
@alkesh26 Just going based on the documentation but my interpretation is that
In that case, I think the behavior you're experiencing is intended. |
Examples based on the conversation in rails#47630.
Motivation / Background
This Pull Request has been created to add deliver callbacks (e.g.
before_deliver,after_deliver,around_deliver) to Action Mailer. The benefit is that it allows delivery observer/interceptor-like behaviors within the context of the instance ofActionMailer::Baserather than operating only on theMailobject.Use cases for this:
delivered_atvalue, especially when usingdeliver_later.message_id(e.g. storing it with a reference to the user or message so that provider webhooks for opened/clicked/spammed can be associated)Additional information
I also found #42139, which is similar but doesn't go all the way of providing the context of the Mailer.
Something to note: Action Mailer's
rescue_fromwraps both the mailer's action processing/rendering step, and the deliver step (effectively twice). I only wanted the deliver callback to wrap deliver, because the existing other*_actioncallback wraps the action processing/rendering step. In pseudocode:Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]