diff options
author | Patrick J Cherry <patrick@bytemark.co.uk> | 2012-01-30 12:30:44 +0000 |
---|---|---|
committer | Patrick J Cherry <patrick@bytemark.co.uk> | 2012-01-30 12:30:44 +0000 |
commit | a75a1088aaa150a5521e1acfa3a372520f3c3995 (patch) | |
tree | 11ec8c3cbb227305630924f62d2a49bb99399388 /lib/mauve/timer.rb | |
parent | 82d493d723c8a3c50b6fdbe3931a49b6b48443b4 (diff) | |
parent | 8ed82944ebd764f1986b3155990b895045b584bc (diff) |
Merge
Diffstat (limited to 'lib/mauve/timer.rb')
-rw-r--r-- | lib/mauve/timer.rb | 100 |
1 files changed, 0 insertions, 100 deletions
diff --git a/lib/mauve/timer.rb b/lib/mauve/timer.rb deleted file mode 100644 index 5a43b60..0000000 --- a/lib/mauve/timer.rb +++ /dev/null @@ -1,100 +0,0 @@ -# encoding: UTF-8 -require 'mauve/alert' -require 'mauve/notifier' -require 'mauve/mauve_thread' -require 'thread' -require 'log4r' - -module Mauve - - # - # This is the thread that looks for reminders and heartbeat alerts to poll. - # - class Timer < MauveThread - - include Singleton - - def initialize - # - # Set the default polling interval to zero.. - # - self.poll_every = 0 - - super - end - - private - - # This is the trigger for heartbeats and reminders. - # - # It looks up the next event, and sleeps until it is due. If an update - # comes in (via the processor) it is broken out of its sleep, and starts - # again when woken up. - # - def main_loop - # - # Get the next alert. - # - next_alert = Alert.find_next_with_event - - # - # If we didn't find an alert, or the alert we found is due in the future, - # look for the next alert_changed object. - # - if next_alert.nil? or next_alert.due_at > Time.now - next_alert_changed = AlertChanged.find_next_with_event - end - - if next_alert_changed.nil? and next_alert.nil? - next_to_notify = nil - - elsif next_alert.nil? or next_alert_changed.nil? - next_to_notify = (next_alert || next_alert_changed) - - else - next_to_notify = ( next_alert.due_at < next_alert_changed.due_at ? next_alert : next_alert_changed ) - - end - - # - # Nothing to notify? - # - if next_to_notify.nil? - # - # Sleep indefinitely - # - logger.info("Nothing to notify about -- snoozing for a while.") - sleep_loops = 600 - else - # - # La la la nothing to do. - # - logger.info("Next to notify: #{next_to_notify} #{next_to_notify.is_a?(AlertChanged) ? "(reminder)" : "(heartbeat)"} -- snoozing until #{next_to_notify.due_at.iso8601}") - sleep_loops = ((next_to_notify.due_at - Time.now).to_f / 0.1).round.to_i - end - - sleep_loops = 1 if sleep_loops.nil? or sleep_loops < 1 - - # - # Ah-ha! Sleep with a break clause. - # - sleep_loops.times do - # - # Start again if the situation has changed. - # - break if self.should_stop? - - # - # This is a rate-limiting step for alerts. - # - Kernel.sleep 0.1 - end - - return if self.should_stop? or next_to_notify.nil? - - next_to_notify.poll - end - - end - -end |