aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve/alert_group.rb
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2012-04-17 11:14:35 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2012-04-17 11:14:35 +0100
commitc8d16b7511969edbde58bc49ef44e0ff63e5cb8f (patch)
tree54679f51c429e0cb449581c96edbfd9db07175de /lib/mauve/alert_group.rb
parent2cca449f78116aa02072e2e6c5036f63c2ec962b (diff)
* DuringRunner#now? caches its answer, indexed by time. The cache is renewed
on reinitialization. * AlertGroup#notify now initialises and keeps track of each DuringRunner to ensure cache usage.
Diffstat (limited to 'lib/mauve/alert_group.rb')
-rw-r--r--lib/mauve/alert_group.rb41
1 files changed, 32 insertions, 9 deletions
diff --git a/lib/mauve/alert_group.rb b/lib/mauve/alert_group.rb
index aa47ef6..31d9cc8 100644
--- a/lib/mauve/alert_group.rb
+++ b/lib/mauve/alert_group.rb
@@ -153,16 +153,39 @@ module Mauve
return false
end
+ during_runners = []
+
#
# 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, at)
- if reminder_time.nil? or (!this_time.nil? and reminder_time > this_time)
- this_time
- else
- reminder_time
- end
+
+ remind_at = nil
+ notifications.each do |notification|
+ #
+ # Create a new during_runner for this notification clause, and keep it
+ # handy.
+ #
+ during_runner = DuringRunner.new(at, alert, &notification.during)
+ during_runners << during_runner
+
+ #
+ # Work out the next reminder time
+ #
+ this_remind_at = notification.remind_at_next(alert, during_runner)
+
+ #
+ # Skip this one if no reminder time can be found
+ #
+ next if this_remind_at.nil?
+
+ #
+ # Set the next reminder time if we've not had one already.
+ #
+ remind_at = this_remind_at if remind_at.nil?
+
+ #
+ # We need the next soonest reminder time.
+ #
+ remind_at = this_remind_at if remind_at > this_remind_at
end
#
@@ -186,7 +209,7 @@ module Mauve
#
sent_to = []
notifications.each do |notification|
- sent_to << notification.notify(alert, sent_to, at)
+ sent_to << notification.notify(alert, sent_to, during_runners.shift)
end
return (sent_to.length > 0)