Class: NewRelic::Agent::InfiniteTracing::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/infinite_tracing/worker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &job) ⇒ Worker

Returns a new instance of Worker.



15
16
17
18
19
20
21
22
# File 'lib/infinite_tracing/worker.rb', line 15

def initialize name, &job
  @name = name
  @job = job
  @error = nil
  @worker_thread = nil
  @lock = Mutex.new
  @lock.synchronize { start_thread }
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



13
14
15
# File 'lib/infinite_tracing/worker.rb', line 13

def error
  @error
end

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/infinite_tracing/worker.rb', line 13

def name
  @name
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/infinite_tracing/worker.rb', line 32

def error?
  !!@error
end

#join(timeout = nil) ⇒ Object



36
37
38
39
40
# File 'lib/infinite_tracing/worker.rb', line 36

def join timeout = nil
  return unless @worker_thread
  NewRelic::Agent.logger.debug "joining worker #{@name} thread..."
  @worker_thread.join timeout
end

#statusObject



24
25
26
27
28
29
30
# File 'lib/infinite_tracing/worker.rb', line 24

def status
  return "error" if error?
  @lock.synchronize do
    return "stopped" if @worker_thread.nil?
    @worker_thread.status || "idle"
  end
end

#stopObject



42
43
44
45
46
47
48
49
# File 'lib/infinite_tracing/worker.rb', line 42

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