Gracefully handle SMTP user input errors (e.g. incorrect email addresses) to prevent Sidekiq retries
Closes https://github.com/gitlabhq/gitlabhq/issues/9560
This commit is contained in:
parent
55fc58bda4
commit
001c8cd0ee
3 changed files with 54 additions and 14 deletions
|
@ -6,6 +6,7 @@ v 8.0.0 (unreleased)
|
|||
- Faster merge
|
||||
- Ability to fetch merge requests from refs/merge-requests/:id
|
||||
- Allow displaying of archived projects in the admin interface (Artem Sidorenko)
|
||||
- Gracefully handle SMTP user input errors (e.g. incorrect email addresses) to prevent Sidekiq retries (Stan Hu)
|
||||
|
||||
v 7.14.0 (unreleased)
|
||||
- Update default robots.txt rules to disallow crawling of irrelevant pages (Ben Bodenmiller)
|
||||
|
|
|
@ -42,6 +42,7 @@ class EmailsOnPushWorker
|
|||
end
|
||||
|
||||
recipients.split(" ").each do |recipient|
|
||||
begin
|
||||
Notify.repository_push_email(
|
||||
project_id,
|
||||
recipient,
|
||||
|
@ -53,6 +54,10 @@ class EmailsOnPushWorker
|
|||
send_from_committer_email: send_from_committer_email,
|
||||
disable_diffs: disable_diffs
|
||||
).deliver
|
||||
# These are input errors and won't be corrected even if Sidekiq retries
|
||||
rescue Net::SMTPFatalError, Net::SMTPSyntaxError => e
|
||||
logger.info("Failed to send e-mail for project '#{project.name_with_namespace}' to #{recipient}: #{e}")
|
||||
end
|
||||
end
|
||||
ensure
|
||||
compare = nil
|
||||
|
|
34
spec/workers/emails_on_push_worker_spec.rb
Normal file
34
spec/workers/emails_on_push_worker_spec.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe EmailsOnPushWorker do
|
||||
include RepoHelpers
|
||||
|
||||
let(:project) { create(:project) }
|
||||
let(:user) { create(:user) }
|
||||
let(:data) { Gitlab::PushDataBuilder.build_sample(project, user) }
|
||||
|
||||
subject { EmailsOnPushWorker.new }
|
||||
|
||||
before do
|
||||
allow(Project).to receive(:find).and_return(project)
|
||||
end
|
||||
|
||||
describe "#perform" do
|
||||
it "sends mail" do
|
||||
subject.perform(project.id, user.email, data.stringify_keys)
|
||||
|
||||
email = ActionMailer::Base.deliveries.last
|
||||
expect(email.subject).to include('Change some files')
|
||||
expect(email.to).to eq([user.email])
|
||||
end
|
||||
|
||||
it "gracefully handles an input SMTP error" do
|
||||
ActionMailer::Base.deliveries.clear
|
||||
allow(Notify).to receive(:repository_push_email).and_raise(Net::SMTPFatalError)
|
||||
|
||||
subject.perform(project.id, user.email, data.stringify_keys)
|
||||
|
||||
expect(ActionMailer::Base.deliveries.count).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue