diff options
author | Patrick J Cherry <patrick@bytemark.co.uk> | 2011-08-31 12:19:48 +0100 |
---|---|---|
committer | Patrick J Cherry <patrick@bytemark.co.uk> | 2011-08-31 12:19:48 +0100 |
commit | b87b69ca3fb266bdb5de88b9e77da54e23e370a5 (patch) | |
tree | 94698670ecd9b8562ae41b0ab793fac821f91f97 /lib/mauve/person.rb | |
parent | 36543941d784715e962599f7bf73f4680387e610 (diff) |
Fixed up alert suppression to be less jumpy
Diffstat (limited to 'lib/mauve/person.rb')
-rw-r--r-- | lib/mauve/person.rb | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/lib/mauve/person.rb b/lib/mauve/person.rb index 60ad60a..c26c456 100644 --- a/lib/mauve/person.rb +++ b/lib/mauve/person.rb @@ -8,10 +8,7 @@ module Mauve attr_reader :notification_thresholds, :last_pop3_login def initialize(*args) - # - # By default send 10 thresholds in a minute maximum - # - @notification_thresholds = { 60 => Array.new(10) } + @notification_thresholds = nil @suppressed = false # # TODO fix up web login so pop3 can be used as a proxy. @@ -25,7 +22,14 @@ module Mauve def suppressed? @suppressed end - + + def notification_thresholds + # + # By default send 10 thresholds in a minute maximum + # + @notification_thresholds ||= { } + end + # This class implements an instance_eval context to execute the blocks # for running a notification block for each person. # @@ -86,6 +90,7 @@ module Mauve end # + # # Sends the alert # def send_alert(level, alert) @@ -93,20 +98,21 @@ module Mauve was_suppressed = self.suppressed? - @suppressed = @notification_thresholds.any? do |period, previous_alert_times| + @suppressed = self.notification_thresholds.any? do |period, previous_alert_times| # # Choose the second one as the first. # first = previous_alert_times[1] - first.is_a?(Time) and (now - first) < period + last = previous_alert_times[-1] + + first.is_a?(Time) and ( + (now - first) < period or + (was_suppressed and (now - last) < period) + ) end - if self.suppressed? - logger.info("Suspending further notifications to #{username} until further notice.") unless was_suppressed - else - logger.info "Starting to send notifications again for #{username}." if was_suppressed - end + logger.info "Starting to send notifications again for #{username}." if was_suppressed and not self.suppressed? # # We only suppress notifications if we were suppressed before we started, @@ -135,12 +141,12 @@ module Mauve # # Remember that we've sent an alert # - @notification_thresholds.each do |period, previous_alert_times| + self.notification_thresholds.each do |period, previous_alert_times| # # Hmm.. not sure how to make this thread-safe. # - @notification_thresholds[period].push Time.now - @notification_thresholds[period].shift + self.notification_thresholds[period].push Time.now + self.notification_thresholds[period].shift end return true |