commit 048f17d2e5dc093dabd6b450ed5a96df0c969082
parent 807fd49262555879f0ad3324cfc245e1e1491d7e
Author: Rich Lane <rlane@club.cc.cmu.edu>
Date: Sat, 27 Feb 2010 09:57:28 -0800
forgot to add idle.rb
Diffstat:
1 file changed, 42 insertions(+), 0 deletions(-)
diff --git a/lib/sup/idle.rb b/lib/sup/idle.rb
@@ -0,0 +1,42 @@
+require 'thread'
+
+module Redwood
+
+class IdleManager
+ include Singleton
+
+ IDLE_THRESHOLD = 60
+
+ def initialize
+ @no_activity_since = Time.now
+ @idle = false
+ @thread = nil
+ end
+
+ def ping
+ if @idle
+ UpdateManager.relay self, :unidle, Time.at(@no_activity_since)
+ @idle = false
+ end
+ @no_activity_since = Time.now
+ end
+
+ def start
+ @thread = Redwood::reporting_thread("checking for idleness") do
+ while true
+ sleep 1
+ if !@idle and Time.now.to_i - @no_activity_since.to_i >= IDLE_THRESHOLD
+ UpdateManager.relay self, :idle, Time.at(@no_activity_since)
+ @idle = true
+ end
+ end
+ end
+ end
+
+ def stop
+ @thread.kill if @thread
+ @thread = nil
+ end
+end
+
+end