diff options
author | Patrick J Cherry <patrick@bytemark.co.uk> | 2012-04-16 20:54:38 +0100 |
---|---|---|
committer | Patrick J Cherry <patrick@bytemark.co.uk> | 2012-04-16 20:54:38 +0100 |
commit | 2cca449f78116aa02072e2e6c5036f63c2ec962b (patch) | |
tree | ba06e0f8d59a50847b5a7827f07b603e9793aa68 /lib | |
parent | ccd064ab3e7e140e851f84e9d1e7f3b987c7b9d1 (diff) |
Added time-fixation when processing "during" clauses, I think.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/mauve/alert.rb | 4 | ||||
-rw-r--r-- | lib/mauve/alert_changed.rb | 2 | ||||
-rw-r--r-- | lib/mauve/alert_group.rb | 15 | ||||
-rw-r--r-- | lib/mauve/notification.rb | 14 |
4 files changed, 20 insertions, 15 deletions
diff --git a/lib/mauve/alert.rb b/lib/mauve/alert.rb index 5a3d181..706b0e3 100644 --- a/lib/mauve/alert.rb +++ b/lib/mauve/alert.rb @@ -400,12 +400,12 @@ module Mauve # Send a notification for this alert. # # @return [Boolean] Showing if an alert has been sent. - def notify + def notify(at = Time.now) if self.alert_group.nil? logger.warn "Could not notify for #{self} since there are no matching alert groups" false else - self.alert_group.notify(self) + self.alert_group.notify(self, at) end end diff --git a/lib/mauve/alert_changed.rb b/lib/mauve/alert_changed.rb index 9b2bea4..7cfdb76 100644 --- a/lib/mauve/alert_changed.rb +++ b/lib/mauve/alert_changed.rb @@ -98,7 +98,7 @@ module Mauve return save end - alert_group.notify(alert) + alert_group.notify(alert, Time.now) # # Need to make sure this reminder is cleared. # diff --git a/lib/mauve/alert_group.rb b/lib/mauve/alert_group.rb index 2f234ec..aa47ef6 100644 --- a/lib/mauve/alert_group.rb +++ b/lib/mauve/alert_group.rb @@ -135,13 +135,16 @@ module Mauve # @return [Log4r::Logger] def logger ; self.class.logger ; end - # Signals that a given alert (which is assumed to belong in this group) - # has undergone a significant change. We resend this to every notify list. + # Signals that a given alert (which is assumed to belong in this group) has + # undergone a significant change. We resend this to every notify list. + # The time is used to determine the time to be used when evaluating + # "during" blocks in the notifier clauses. # # @param [Mauve::Alert] alert + # @param [Time] at # # @return [Boolean] indicates success or failure of alert. - def notify(alert) + def notify(alert, at=Time.now) # # If there are no notifications defined. # @@ -154,7 +157,7 @@ module Mauve # This is where we set the reminder -- i.e. on a per-alert-group basis. # remind_at = notifications.inject(nil) do |reminder_time, notification| - this_time = notification.remind_at_next(alert) + this_time = notification.remind_at_next(alert, at) if reminder_time.nil? or (!this_time.nil? and reminder_time > this_time) this_time else @@ -170,7 +173,7 @@ module Mauve :level => level.to_s, :alert_id => alert.id, :person => self.name, - :at => Time.now, + :at => at, :update_type => alert.update_type, :remind_at => remind_at, :was_relevant => true) @@ -183,7 +186,7 @@ module Mauve # sent_to = [] notifications.each do |notification| - sent_to << notification.notify(alert, sent_to) + sent_to << notification.notify(alert, sent_to, at) end return (sent_to.length > 0) diff --git a/lib/mauve/notification.rb b/lib/mauve/notification.rb index 920f1b1..a9795f3 100644 --- a/lib/mauve/notification.rb +++ b/lib/mauve/notification.rb @@ -195,7 +195,7 @@ module Mauve # @param [Array] already_sent_to A list of people that have already received this alert. # # @return [Array] The list of people that have received this alert. - def notify(alert, already_sent_to = []) + def notify(alert, already_sent_to = [], at=Time.now) if people.nil? or people.empty? logger.warn "No people found in for notification #{list}" @@ -203,7 +203,7 @@ module Mauve end # Should we notify at all? - return already_sent_to unless DuringRunner.new(Time.now, alert, &during).now? + return already_sent_to unless DuringRunner.new(at, alert, &during).now? people.collect do |person| case person @@ -236,13 +236,15 @@ module Mauve # @param [Mauve::Alert] alert The alert in question # @return [Time or nil] The time a reminder should get sent, or nil if it # should never get sent again. - def remind_at_next(alert) + def remind_at_next(alert, at = Time.now) return nil unless alert.raised? - if DuringRunner.new(Time.now, alert, &during).now? - return DuringRunner.new(Time.now, alert, &during).find_next(every) + dr = DuringRunner.new(at, alert, &during) + + if dr.now? + return dr.find_next(every) else - return DuringRunner.new(Time.now, alert, &during).find_next() + return dr.find_next() end end |