class Garcon::ThreadPoolWorker

@!visibility private

Public Class Methods

new(queue, parent) click to toggle source

@!visibility private

# File lib/garcon/task/thread_pool/worker.rb, line 29
def initialize(queue, parent)
  @queue         = queue
  @parent        = parent
  @mutex         = Mutex.new
  @last_activity = Garcon.monotonic_time
  @thread        = nil
end

Public Instance Methods

dead?() click to toggle source

@!visibility private

# File lib/garcon/task/thread_pool/worker.rb, line 38
def dead?
  return @mutex.synchronize do
    @thread.nil? ? false : ! @thread.alive?
  end
end
kill() click to toggle source

@!visibility private

# File lib/garcon/task/thread_pool/worker.rb, line 57
def kill
  @mutex.synchronize do
    Thread.kill(@thread) unless @thread.nil?
    @thread = nil
  end
end
last_activity() click to toggle source

@!visibility private

# File lib/garcon/task/thread_pool/worker.rb, line 45
def last_activity
  @mutex.synchronize { @last_activity }
end
run(thread = Thread.current) click to toggle source

@!visibility private

# File lib/garcon/task/thread_pool/worker.rb, line 65
def run(thread = Thread.current)
  @mutex.synchronize do
    raise StandardError, 'already running' unless @thread.nil?
    @thread = thread
  end

  loop do
    task = @queue.pop
    if task == :stop
      @thread = nil
      @parent.on_worker_exit(self)
      break
    end

    begin
      task.last.call(*task.first)
    rescue => e
      Chef::Log.debug "Caught exception => #{e}"
    ensure
      @last_activity = Garcon.monotonic_time
      @parent.on_end_task
    end
  end
end
status() click to toggle source
# File lib/garcon/task/thread_pool/worker.rb, line 49
def status
  @mutex.synchronize do
    return 'not running' if @thread.nil?
    @thread.status
  end
end