From da9ef07cfa2dfd26d1e8efdce5598a7ac7806271 Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Mon, 22 Aug 2011 12:01:17 +0100 Subject: * Race condition fixed (fixes #1861). * Reminders get sent at start of during period (fixes #1821) --- lib/mauve/alert_group.rb | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'lib/mauve/alert_group.rb') diff --git a/lib/mauve/alert_group.rb b/lib/mauve/alert_group.rb index 114c39b..df76f40 100644 --- a/lib/mauve/alert_group.rb +++ b/lib/mauve/alert_group.rb @@ -95,16 +95,45 @@ module Mauve # # If there are no notifications defined. # - if notifications.nil? + if notifications.nil? logger.warn("No notifications found for #{self.inspect}") return end + # + # 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) + if reminder_time.nil? or (!this_time.nil? and reminder_time > this_time) + this_time + else + reminder_time + end + end + + # + # OK got the next reminder time. + # + unless remind_at.nil? + this_reminder = AlertChanged.new( + :level => level.to_s, + :alert_id => alert.id, + :person => self.name, + :at => Time.now, + :update_type => alert.update_type, + :remind_at => remind_at, + :was_relevant => true) + + this_reminder.save + end + # # The notifications are specified in the config file. # + sent_to = [] notifications.each do |notification| - notification.notify(alert) + sent_to = notification.notify(alert, sent_to) end end -- cgit v1.2.1