diff options
author | Patrick J Cherry <patrick@bytemark.co.uk> | 2011-09-16 12:40:49 +0100 |
---|---|---|
committer | Patrick J Cherry <patrick@bytemark.co.uk> | 2011-09-16 12:40:49 +0100 |
commit | ef42591e391efeee625ac139ed6e9c07a3c38eb0 (patch) | |
tree | 2adef2f0c745af5cf0b485532249a716e2f71e3e | |
parent | d67ae212a8bfd5b9e4c0ae6296a66f97b57af61c (diff) |
Remove the canary
-rw-r--r-- | lib/canary.rb | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/lib/canary.rb b/lib/canary.rb deleted file mode 100644 index afe3a16..0000000 --- a/lib/canary.rb +++ /dev/null @@ -1,55 +0,0 @@ -# encoding: UTF-8 -require 'logger' - -# A little canary class to make sure that threads are are overloaded. -class Canary - - # Accessor. - attr_reader :sleep_time - - # Accessor. - attr_reader :threshold - - # Default constructor. - def initialize (st=1, log=nil) - if Float != st.class and Fixnum != st.class - raise ArgumentError.new( - "Expected either Fixnum or Float for time to sleep, got #{st.class}.") - end - @sleep_time = st - @threshold = (0.05 * @sleep_time) + @sleep_time - @logger = log - end - - # Runs the check. - def run - loop do - self.do_test() - end - end - - def do_test - time_start = Time.now - sleep(@sleep_time) - time_end = Time.now - time_elapsed = (time_end - time_start).abs - if @threshold < time_elapsed - @logger.fatal("Time elapsed is #{time_elapsed} > #{@threshold} therefore Canary is dead.") - return false - else - @logger.debug("Time elapsed is #{time_elapsed} < #{@threshold} therefore Canary is alive.") - return true - end - end - - # Starts a canary in a thread. - def self.start (st=1, log=nil) - #Thread.abort_on_exception = true - thr = Thread.new() do - Thread.current[:name] = "Canary Thread" - twiti = Canary.new(st, log) - twiti.run() - end - end - -end |