Commit 85d12bd6928f7859742439c4e034cf12803efee2
Committed by
Sergey Nartimov
1 parent
2ee7c9db
Exists in
master
and in
1 other branch
throttle email notificatiions
Showing
4 changed files
with
25 additions
and
10 deletions
Show diff stats
app/models/app.rb
... | ... | @@ -103,6 +103,10 @@ class App |
103 | 103 | end |
104 | 104 | alias :notify_on_errs? :notify_on_errs |
105 | 105 | |
106 | + def notifiable? | |
107 | + notify_on_errs? && notification_recipients.any? | |
108 | + end | |
109 | + | |
106 | 110 | def notify_on_deploys |
107 | 111 | !(super == false) |
108 | 112 | end |
... | ... | @@ -185,6 +189,10 @@ class App |
185 | 189 | name <=> other.name |
186 | 190 | end |
187 | 191 | |
192 | + def email_at_notices | |
193 | + Errbit::Config.per_app_email_at_notices ? read_attribute(:email_at_notices) : Errbit::Config.email_at_notices | |
194 | + end | |
195 | + | |
188 | 196 | protected |
189 | 197 | |
190 | 198 | def store_cached_attributes_on_problems | ... | ... |
app/models/notice.rb
... | ... | @@ -94,6 +94,18 @@ class Notice |
94 | 94 | backtrace_lines.in_app |
95 | 95 | end |
96 | 96 | |
97 | + def similar_count | |
98 | + problem.notices_count | |
99 | + end | |
100 | + | |
101 | + def notifiable? | |
102 | + app.email_at_notices.include?(similar_count) | |
103 | + end | |
104 | + | |
105 | + def should_notify? | |
106 | + app.notifiable? && notifiable? | |
107 | + end | |
108 | + | |
97 | 109 | protected |
98 | 110 | |
99 | 111 | def increase_counter_cache | ... | ... |
app/models/notice_observer.rb
... | ... | @@ -7,16 +7,7 @@ class NoticeObserver < Mongoid::Observer |
7 | 7 | notice.app.notification_service.create_notification(notice.problem) |
8 | 8 | end |
9 | 9 | |
10 | - if notice.app.notification_recipients.any? | |
11 | - Mailer.err_notification(notice).deliver | |
12 | - end | |
10 | + Mailer.err_notification(notice).deliver if notice.should_notify? | |
13 | 11 | end |
14 | 12 | |
15 | - private | |
16 | - | |
17 | - def should_notify? notice | |
18 | - app = notice.app | |
19 | - app.notify_on_errs? and (app.notification_recipients.any? or !app.notification_service.nil?) and | |
20 | - (app.email_at_notices or Errbit::Config.email_at_notices).include?(notice.problem.notices_count) | |
21 | - end | |
22 | 13 | end | ... | ... |
spec/controllers/apps_controller_spec.rb
... | ... | @@ -250,6 +250,10 @@ describe AppsController do |
250 | 250 | end |
251 | 251 | |
252 | 252 | context "changing email_at_notices" do |
253 | + before do | |
254 | + Errbit::Config.per_app_email_at_notices = true | |
255 | + end | |
256 | + | |
253 | 257 | it "should parse legal csv values" do |
254 | 258 | put :update, :id => @app.id, :app => { :email_at_notices => '1, 4, 7,8, 10' } |
255 | 259 | @app.reload | ... | ... |