Skip to content

Commit

Permalink
Update RequestMailer to use deliver_later
Browse files Browse the repository at this point in the history
Deliver emails in the background job instead of doing it inline.
  • Loading branch information
gbp committed Jul 31, 2024
1 parent 3d7e9cf commit 61de041
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
12 changes: 6 additions & 6 deletions app/mailers/request_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,13 @@ def self.alert_overdue_requests
overdue_alert(
info_request,
info_request.user
).deliver_now
).deliver_later
elsif calculated_status == 'waiting_response_very_overdue'
RequestMailer.
very_overdue_alert(
info_request,
info_request.user
).deliver_now
).deliver_later
else
raise "unknown request status"
end
Expand Down Expand Up @@ -387,7 +387,7 @@ def self.alert_new_response_reminders_internal(days_since, type_code)
new_response_reminder_alert(
info_request,
last_response_message
).deliver_now
).deliver_later
store_sent.save!
end
end
Expand Down Expand Up @@ -434,7 +434,7 @@ def self.alert_not_clarified_request
RequestMailer.not_clarified_alert(
info_request,
last_response_message
).deliver_now
).deliver_later
end
store_sent.save!
end
Expand Down Expand Up @@ -508,12 +508,12 @@ def self.alert_comment_on_request
info_request,
count,
earliest_unalerted_comment_event.comment
).deliver_now
).deliver_later
elsif count == 1
RequestMailer.comment_on_alert(
info_request,
last_comment_event.comment
).deliver_now
).deliver_later
else
raise "internal error"
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def report!(reason, message, user)
"comment: #{comment_url(self)} " \
"\nadmin: #{edit_admin_comment_url(self)}"

RequestMailer.requires_admin(info_request, user, message).deliver_now
RequestMailer.requires_admin(info_request, user, message).deliver_later

info_request.log_event(
'report_comment',
Expand Down
6 changes: 3 additions & 3 deletions app/models/info_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ def receive(email, raw_email_data, *args)
)
user.notify(info_request_event)
else
RequestMailer.new_response(self, incoming_message).deliver_now
RequestMailer.new_response(self, incoming_message).deliver_later
end
end
end
Expand Down Expand Up @@ -1022,13 +1022,13 @@ def set_described_state(new_state, set_by = nil, message = "")
if old_described_state != described_state && requires_admin?
# Check there is someone to send the message "from"
if set_by && user
RequestMailer.requires_admin(self, set_by, message).deliver_now
RequestMailer.requires_admin(self, set_by, message).deliver_later
end
end

unless set_by.nil? || is_actual_owning_user?(set_by) || described_state == 'attention_requested'
RequestMailer.
old_unclassified_updated(self).deliver_now unless is_external?
old_unclassified_updated(self).deliver_later unless is_external?
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/classifications_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def post_status(status, message: nil)
it 'should send an email to the requester letting them know someone has
updated the status of their request' do
mail_mock = double('mail')
allow(mail_mock).to receive :deliver_now
allow(mail_mock).to receive :deliver_later
expect(RequestMailer).to receive(:old_unclassified_updated).
and_return(mail_mock)
post_status('rejected')
Expand Down
1 change: 1 addition & 0 deletions spec/support/email_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def rebuild_raw_emails(info_request)
end

def deliveries
perform_enqueued_jobs
@deliveries ||= []
@deliveries += ActionMailer::Base.deliveries
ActionMailer::Base.deliveries.clear
Expand Down

0 comments on commit 61de041

Please sign in to comment.