Class: Lifeguard::Reaper

Inherits:
Object
  • Object
show all
Defined in:
lib/lifeguard/reaper.rb

Instance Method Summary collapse

Constructor Details

#initialize(threadpool, reaping_interval) ⇒ Reaper

Constructor



6
7
8
9
10
11
# File 'lib/lifeguard/reaper.rb', line 6

def initialize(threadpool, reaping_interval)
  @threadpool = threadpool
  @reaping_interval = reaping_interval
  @thread = ::Thread.new { self.run! }
  ::Thread.pass until alive?
end

Instance Method Details

#alive?Boolean

Public Instance Methods

Returns:

  • (Boolean)


16
17
18
# File 'lib/lifeguard/reaper.rb', line 16

def alive?
  @thread.alive?
end

#run!Object



20
21
22
23
24
25
26
27
28
# File 'lib/lifeguard/reaper.rb', line 20

def run!
  loop do
    sleep(@reaping_interval)
    @threadpool.prune_busy_threads if @threadpool
    @threadpool.timeout! if @threadpool
  end
rescue
  retry
end