aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve/alert_changed.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/alert_changed.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/alert_changed.rb')
-rw-r--r--lib/mauve/alert_changed.rb100
1 files changed, 16 insertions, 84 deletions
diff --git a/lib/mauve/alert_changed.rb b/lib/mauve/alert_changed.rb
index 9840b84..9b74396 100644
--- a/lib/mauve/alert_changed.rb
+++ b/lib/mauve/alert_changed.rb
@@ -19,7 +19,6 @@ module Mauve
property :remind_at, Time
# property :updated_at, Time, :required => true
-
def inspect
"#<AlertChanged #{id}: alert_id #{alert_id}, for #{person}, update_type #{update_type}>"
end
@@ -44,35 +43,6 @@ module Mauve
Log4r::Logger.new self.class.to_s
end
- ## Checks to see if a raise was send to the person.
- #
- # @TODO: Recurence is broken in ruby, change this so that it does not
- # use it.
- #
- # @author Matthew Bloch
- # @return [Boolean] true if it was relevant, false otherwise.
- def was_relevant_when_raised?
-
- if "acknowledged" == update_type and true == was_relevant
- return true
- end
-
- return was_relevant if update_type == "raised"
-
- previous = AlertChanged.first(:id.lt => id,
- :alert_id => alert_id,
- :person => person)
- if previous
- previous.was_relevant_when_raised?
- else
- # a bug, but hardly inconceivable :)
- logger.info("Could not see that #{alert} was raised with #{person} "+
- "but further updates exist (e.g. #{self}) "+
- "- you may see spurious notifications as a result")
- true
- end
- end
-
# Sends a reminder about this alert state change, or forget about it if
# the alert has been acknowledged
#
@@ -82,69 +52,31 @@ module Mauve
destroy!
return false
end
-
-
- alert_group = AlertGroup.matches(alert)[0]
-
- if !alert_group || alert.acknowledged?
- logger.info((alert_group ?
- "Alert already acknowledged" :
- "No alert group matches any more"
- ) + " => no reminder due for #{self.alert.inspect}"
- )
+ if !alert_group
+ logger.info("No alert group matches any more. Clearing reminder for #{self.alert}.")
self.remind_at = nil
- save
- else
- logger.info "Sending a reminder for #{self.alert.inspect}"
-
- saved = false
- unless alert_group.notifications.nil?
+ return save
+ end
- alert_group.notifications.each do |notification|
- #
- # Build an array of people that could/should be notified.
- #
- notification_people = []
+ if alert.acknowledged?
+ logger.info("Alert already acknowledged. Clearing reminder due for #{self.alert}.")
+ self.remind_at = nil
+ return save
+ end
- notification.people.each do |np|
- case np
- when Person
- notification_people << np.username
- when PeopleList
- notification_people += np.list
- end
- end
+ alert_group.notify(alert)
+ #
+ # Need to make sure this reminder is cleared.
+ #
+ self.remind_at = nil
- #
- # For each person, send a notification
- #
- notification_people.sort.uniq.each do |np|
- if np == self.person
- #
- # Only remind if the time is right.
- #
- if DuringRunner.new(Time.now, alert, &notification.during).now?
- Configuration.current.people[np].send_alert(level, alert)
- end
- self.remind_at = notification.remind_at_next(alert)
- save
- saved = true
- end
- end
- end
- end
-
- if !saved
- logger.warn("#{self.inspect} did not match any people, maybe configuration has changed but I'm going to delete this and not try to remind anyone again")
- destroy!
- end
- end
+ save
end
def due_at # mimic interface from Alert
- remind_at ? remind_at.to_time : nil
+ remind_at ? remind_at : nil
end
def poll # mimic interface from Alert