Class: Redwood::IdleManager
- Includes:
- Singleton
- Defined in:
- lib/sup/idle.rb
Constant Summary collapse
- IDLE_THRESHOLD =
60
Instance Method Summary collapse
-
#initialize ⇒ IdleManager
constructor
A new instance of IdleManager.
- #ping ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Methods included from Singleton
Constructor Details
#initialize ⇒ IdleManager
Returns a new instance of IdleManager.
10 11 12 13 14 |
# File 'lib/sup/idle.rb', line 10 def initialize @no_activity_since = Time.now @idle = false @thread = nil end |
Instance Method Details
#ping ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/sup/idle.rb', line 16 def ping if @idle UpdateManager.relay self, :unidle, Time.at(@no_activity_since) @idle = false end @no_activity_since = Time.now end |
#start ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/sup/idle.rb', line 24 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 |
#stop ⇒ Object
36 37 38 39 |
# File 'lib/sup/idle.rb', line 36 def stop @thread.kill if @thread @thread = nil end |