-
Notifications
You must be signed in to change notification settings - Fork 58
[1127] Add an ENV variable to log rake emails #1316
Conversation
@@ -6,7 +6,8 @@ task email_checkin_reminder: :environment do | |||
Rails.logger.info "Found #{upcoming_reservations.size} reservations due "\ | |||
'for check-in. Sending reminder emails...' | |||
upcoming_reservations.each do |upcoming_reservation| | |||
UserMailer.reservation_status_update(upcoming_reservation).deliver | |||
m = UserMailer.reservation_status_update(upcoming_reservation).deliver |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can move this into the reservation_status_update
method so it doesn't have to be duplicated in all of the rake tasks; the only exception is in the email_notes_to_admins
task which uses a separate method.
This works fine, but I think we can come up with a DRY-er solution. Is it possible for us to add a method to either both of the Mailer classes ( |
Ooh, never mind! Rails supports Mailer Observers - that looks perfect to me. We'll basically set up an initializer that only creates and registers the Observer if the environment variable is set - if it's registered it will log the sending of each e-mail, which might be overkill but for debugging purposes seems acceptable to me. There's also an SO Thread on creating Observers. Let me know how that sounds! |
is it okay if it logs all emails, not just the ones sent by rake task? |
Yea I think that's fine. This should only be activated for debugging purposes (e.g. we'd need console access to the application server to add it to the |
yup, just wanted to make sure because I'm not sure how to implement this only for specific emails |
51b98d8
to
b31fed0
Compare
this now has tests and is (actually) ready for review! |
@@ -49,6 +50,19 @@ | |||
expect(ActionMailer::Base.deliveries.count).to eq(1) | |||
end | |||
|
|||
it 'logs if the env is set' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these are AWESOME, great work! I'll just test this locally and we should be good to go 😄
This works! Strangely, it's also logging that an e-mail was sent without the flag sent, even at logger level
whereas with the ENV variable set it looks like:
The latter is clearly better since it includes the subject, but I'm wondering if the former has something to do with the fact that I'm in the development environment and just simulating the log level of production. In any case, this does what we need and the code looks good, so let's go those commits squashed! |
Resolves #1127 - Emails are logged via an Observer - Log message contains subject and addressee
5f1ca02
to
bfb3832
Compare
should be good to go |
Note to self: it is true that Rails already logs e-mails, but only logs the recipient. The original issue which inspired this (#1125) was a case where the instance was, in fact, not sending the e-mails we were looking for so I didn't realize that this logging was occurring. In any event, having some more details for debugging (the subject, essentially) is still useful. Merging! |
[1127] Add an ENV variable to log rake emails
Resolves #1127
this shouldn't be merged until #1203 is merged