aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve/notification.rb
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2011-08-17 11:08:07 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2011-08-17 11:08:07 +0100
commit8c8e5ae926e0009743fe92dccb588783640a6022 (patch)
treee23eea583beac0caf5fb3e45a33b4d2ac7796abf /lib/mauve/notification.rb
parent79dcf16ec6d229d6c31e055ed8e6a98327526a3a (diff)
* Reminder notifications now take the same path to notify as initial alerts
* Threading tidied -- processor will not do anything unless the timer has frozen * Person#send_alert now tidied and merged with alert_changed * POP3 server only shows alerts relevant to the user * Server now defaults to using an in-memory SQLite database (good for testing) * Server initializes a blank mauve config. * Tests tidied up
Diffstat (limited to 'lib/mauve/notification.rb')
-rw-r--r--lib/mauve/notification.rb21
1 files changed, 4 insertions, 17 deletions
diff --git a/lib/mauve/notification.rb b/lib/mauve/notification.rb
index dea07a3..8e125be 100644
--- a/lib/mauve/notification.rb
+++ b/lib/mauve/notification.rb
@@ -149,20 +149,6 @@ module Mauve
def logger ; Log4r::Logger.new self.class.to_s ; end
- # Updated code, now takes account of lists of people.
- #
- # @TODO refactor so we can test this more easily.
- #
- # @TODO Make sure that if no notifications is send at all, we log this
- # as an error so that an email is send to the developers. Hum, we
- # could have person.alert_changed return true if a notification was
- # send (false otherwise) and add it to a queue. Then, dequeue till
- # we see a "true" and abort. However, this needs a timeout loop
- # around it and we will slow down the whole notificatin since it
- # will have to wait untill such a time as it gets a true or timeout.
- # Not ideal. A quick fix is to make sure that the clause in the
- # configuration has a fall back that will send an alert in all cases.
- #
def notify(alert)
if people.nil? or people.empty?
@@ -173,6 +159,8 @@ module Mauve
# Should we notify at all?
is_relevant = DuringRunner.new(Time.now, alert, &during).now?
+ n_sent = 0
+
people.collect do |person|
case person
when Person
@@ -184,14 +172,13 @@ module Mauve
[]
end
end.flatten.uniq.each do |person|
- person.send_alert(level, alert, is_relevant, remind_at_next(alert))
+ n_sent += 1 if person.send_alert(self.level, alert, is_relevant, remind_at_next(alert))
end
- return nil
+ return n_sent
end
def remind_at_next(alert)
-
return DuringRunner.new(Time.now, alert, &during).find_next(every) if alert.raised?
return nil