Sha256: f5e74fb545aaeaf50931d8c7c0dc91e4e30504083b0a25adc83efa4777ccd492

Contents?: true

Size: 757 Bytes

Versions: 11

Compression:

Stored size: 757 Bytes

Contents

require 'thread'

module Redwood

class IdleManager
  include Redwood::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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
sup-1.2 lib/sup/idle.rb
sup-1.1 lib/sup/idle.rb
sup-1.0 lib/sup/idle.rb
sup-0.23 lib/sup/idle.rb
sup-0.22.1 lib/sup/idle.rb
sup-0.22.0 lib/sup/idle.rb
sup-0.21.0 lib/sup/idle.rb
sup-0.20.0 lib/sup/idle.rb
sup-0.19.0 lib/sup/idle.rb
sup-0.18.0 lib/sup/idle.rb
sup-0.17.0 lib/sup/idle.rb