diff options
author | Patrick J Cherry <patrick@bytemark.co.uk> | 2011-04-13 17:03:16 +0100 |
---|---|---|
committer | Patrick J Cherry <patrick@bytemark.co.uk> | 2011-04-13 17:03:16 +0100 |
commit | 89a67770e66d11740948e90a41db6cee0482cf8e (patch) | |
tree | be858515fb789a89d68f94975690ab019813726c /lib/mauve/notifier.rb |
new version.
Diffstat (limited to 'lib/mauve/notifier.rb')
-rw-r--r-- | lib/mauve/notifier.rb | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/lib/mauve/notifier.rb b/lib/mauve/notifier.rb new file mode 100644 index 0000000..e0692f6 --- /dev/null +++ b/lib/mauve/notifier.rb @@ -0,0 +1,66 @@ +require 'mauve/mauve_thread' +require 'mauve/notifiers' +require 'mauve/notifiers/xmpp' + +module Mauve + + class Notifier < MauveThread + + DEFAULT_XMPP_MESSAGE = "Mauve server started." + + include Singleton + + attr_accessor :buffer, :sleep_interval + + def initialize + @buffer = Queue.new + end + + def main_loop + + # + # Cycle through the buffer. + # + sz = @buffer.size + + logger.debug("Notifier buffer is #{sz} in length") if sz > 1 + + (sz > 10 ? 10 : sz).times do + person, level, alert = @buffer.pop + begin + person.do_send_alert(level, alert) + rescue StandardError => ex + logger.debug ex.to_s + logger.debug ex.backtrace.join("\n") + end + end + + end + + def start + super + + Configuration.current.notification_methods['xmpp'].connect if Configuration.current.notification_methods['xmpp'] + end + + def stop + Configuration.current.notification_methods['xmpp'].close + + super + end + + class << self + + def enq(a) + instance.buffer.enq(a) + end + + alias push enq + + end + + end + +end + + |