aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve/notification.rb
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2011-08-22 12:01:17 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2011-08-22 12:01:17 +0100
commitda9ef07cfa2dfd26d1e8efdce5598a7ac7806271 (patch)
treef574227852d475ef772a86366eb8a3c50da1ab1a /lib/mauve/notification.rb
parent8268305f172376b92957096a2154efe34e275b6a (diff)
* Race condition fixed (fixes #1861).
* Reminders get sent at start of during period (fixes #1821)
Diffstat (limited to 'lib/mauve/notification.rb')
-rw-r--r--lib/mauve/notification.rb28
1 files changed, 19 insertions, 9 deletions
diff --git a/lib/mauve/notification.rb b/lib/mauve/notification.rb
index c57d2a9..43de1a7 100644
--- a/lib/mauve/notification.rb
+++ b/lib/mauve/notification.rb
@@ -145,7 +145,6 @@ module Mauve
attr_reader :thread_list
def initialize(people, level)
-
self.level = level
self.every = 300
self.people = people
@@ -153,7 +152,7 @@ module Mauve
def logger ; Log4r::Logger.new self.class.to_s ; end
- def notify(alert)
+ def notify(alert, already_sent_to = [])
if people.nil? or people.empty?
logger.warn "No people found in for notification #{list}"
@@ -161,9 +160,7 @@ module Mauve
end
# Should we notify at all?
- is_relevant = DuringRunner.new(Time.now, alert, &during).now?
-
- n_sent = 0
+ return already_sent_to unless DuringRunner.new(Time.now, alert, &during).now?
people.collect do |person|
case person
@@ -176,16 +173,29 @@ module Mauve
[]
end
end.flatten.uniq.each do |person|
- n_sent += 1 if person.send_alert(self.level, alert, is_relevant, remind_at_next(alert))
+ #
+ # A bit of alert de-bouncing.
+ #
+ if already_sent_to.include?(person.username)
+ logger.info("Already sent notification of #{alert} to #{person.username}")
+ else
+ Server.notification_push([person, level, alert])
+ already_sent_to << person.username
+ end
end
- return n_sent
+ return already_sent_to
end
def remind_at_next(alert)
- return DuringRunner.new(Time.now, alert, &during).find_next(every) if alert.raised?
+ return nil unless alert.raised?
+
+ if DuringRunner.new(Time.now, alert, &during).now?
+ return DuringRunner.new(Time.now, alert, &during).find_next(every)
+ else
+ return DuringRunner.new(Time.now, alert, &during).find_next(0)
+ end
- return nil
end
end