From d41debaa49968bfdfb27bc309f628b6ec8ad492d Mon Sep 17 00:00:00 2001 From: Cyril Mougel Date: Wed, 21 Aug 2013 15:14:01 +0200 Subject: [PATCH] Rescue if there are failure in notification system --- app/models/notice.rb | 4 ++++ spec/models/notice_observer_spec.rb | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 0 deletions(-) diff --git a/app/models/notice.rb b/app/models/notice.rb index 64db1f6..94a42f7 100644 --- a/app/models/notice.rb +++ b/app/models/notice.rb @@ -170,6 +170,8 @@ class Notice def email_notification return true unless should_email? Mailer.err_notification(self).deliver + rescue => e + HoptoadNotifier.notify(e) end ## @@ -177,6 +179,8 @@ class Notice def services_notification return true unless app.notification_service_configured? and should_notify? app.notification_service.create_notification(problem) + rescue => e + HoptoadNotifier.notify(e) end end diff --git a/spec/models/notice_observer_spec.rb b/spec/models/notice_observer_spec.rb index 3a99793..65dc330 100644 --- a/spec/models/notice_observer_spec.rb +++ b/spec/models/notice_observer_spec.rb @@ -24,6 +24,7 @@ describe "Callback on Notice" do end end + describe "email notifications for a resolved issue" do before do Errbit::Config.per_app_email_at_notices = true @@ -41,6 +42,13 @@ describe "Callback on Notice" do and_return(double('email', :deliver => true)) Fabricate(:notice, :err => @err) end + it 'self notify if mailer failed' do + @err.problem.resolve! + Mailer.should_receive(:err_notification). + and_raise(ArgumentError) + HoptoadNotifier.should_receive(:notify) + Fabricate(:notice, :err => @err) + end end describe "should send a notification if a notification service is configured with defaults" do @@ -64,6 +72,30 @@ describe "Callback on Notice" do end end + describe "send a notification if a notification service is configured with defaults but failed" do + let(:app) { Fabricate(:app_with_watcher, + :notify_on_errs => true, + :email_at_notices => [1, 100], :notification_service => Fabricate(:campfire_notification_service))} + let(:err) { Fabricate(:err, :problem => Fabricate(:problem, :app => app, :notices_count => 99)) } + let(:backtrace) { Fabricate(:backtrace) } + + before do + Errbit::Config.per_app_email_at_notices = true + end + + after do + Errbit::Config.per_app_email_at_notices = false + end + + it "send email" do + app.notification_service.should_receive(:create_notification).and_raise(ArgumentError) + Mailer.should_receive(:err_notification).and_return(double(:deliver => true)) + + Notice.create!(:err => err, :message => 'FooError: Too Much Bar', :server_environment => {'environment-name' => 'production'}, + :backtrace => backtrace, :notifier => { 'name' => 'Notifier', 'version' => '1', 'url' => 'http://toad.com' }) + end + end + describe "should not send a notification if a notification service is not configured" do let(:app) { Fabricate(:app, :email_at_notices => [1], :notification_service => Fabricate(:notification_service))} let(:err) { Fabricate(:err, :problem => Fabricate(:problem, :app => app, :notices_count => 100)) } -- libgit2 0.21.2