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.



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

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.



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

def error
  @error
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


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

def error?
  !!@error
end

#join(timeout = nil) ⇒ Object



37
38
39
40
41
42
# 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

#statusObject



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

def status
  return 'error' if error?

  @lock.synchronize do
    return 'stopped' if @worker_thread.nil?

    @worker_thread.status || 'idle'
  end
end

#stopObject



44
45
46
47
48
49
50
51
52
# File 'lib/infinite_tracing/worker.rb', line 44

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