class NewRelic::Agent::InfiniteTracing::Worker

Attributes

error[R]
name[R]

Public Class Methods

new(name, &job) click to toggle source
# File lib/infinite_tracing/worker.rb, line 16
def initialize name, &job
  @name = name
  @job = job
  @error = nil
  @worker_thread = nil
  @lock = Mutex.new
  @lock.synchronize { start_thread }
end

Public Instance Methods

error?() click to toggle source
# File lib/infinite_tracing/worker.rb, line 33
def error?
  !!@error
end
join(timeout=nil) click to toggle source
# File lib/infinite_tracing/worker.rb, line 37
def join timeout=nil
  return unless @worker_thread
  NewRelic::Agent.logger.debug "joining worker #{@name} thread..."
  @worker_thread.join timeout 
end
status() click to toggle source
# File lib/infinite_tracing/worker.rb, line 25
def status
  return "error" if error?
  @lock.synchronize do
    return "stopped" if @worker_thread.nil?
    @worker_thread.status || "idle"
  end
end
stop() click to toggle source
# File lib/infinite_tracing/worker.rb, line 43
def stop
  @lock.synchronize do 
    return unless @worker_thread
    NewRelic::Agent.logger.debug "stopping worker #{@name} thread..."
    @worker_thread.kill
    @worker_thread = nil
  end
end

Private Instance Methods

start_thread() click to toggle source
# File lib/infinite_tracing/worker.rb, line 54
def start_thread
  NewRelic::Agent.logger.debug "starting worker #{@name} thread..."
  @worker_thread = Thread.new do
    catch(:exit) do
      begin
        @job.call
      rescue => err
        @error = err
        raise
      end
    end
  end
  @worker_thread.abort_on_exception = true
  if @worker_thread.respond_to? :report_on_exception
    @worker_thread.report_on_exception = NewRelic::Agent.config[:log_level] == "debug"
  end
end