Class: ScoutApm::BackgroundRecorder
- Inherits:
-
Object
- Object
- ScoutApm::BackgroundRecorder
- Defined in:
- lib/scout_apm/background_recorder.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Instance Method Summary collapse
-
#initialize(logger) ⇒ BackgroundRecorder
constructor
A new instance of BackgroundRecorder.
- #record!(request) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #thread_func ⇒ Object
Constructor Details
#initialize(logger) ⇒ BackgroundRecorder
Returns a new instance of BackgroundRecorder.
11 12 13 14 |
# File 'lib/scout_apm/background_recorder.rb', line 11 def initialize(logger) @logger = logger @queue = Queue.new end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
9 10 11 |
# File 'lib/scout_apm/background_recorder.rb', line 9 def logger @logger end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
7 8 9 |
# File 'lib/scout_apm/background_recorder.rb', line 7 def queue @queue end |
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
8 9 10 |
# File 'lib/scout_apm/background_recorder.rb', line 8 def thread @thread end |
Instance Method Details
#record!(request) ⇒ Object
26 27 28 29 |
# File 'lib/scout_apm/background_recorder.rb', line 26 def record!(request) start unless @thread.alive? @queue.push(request) end |
#start ⇒ Object
16 17 18 19 20 |
# File 'lib/scout_apm/background_recorder.rb', line 16 def start logger.info("Starting BackgroundRecorder") @thread = Thread.new(&method(:thread_func)) self end |
#stop ⇒ Object
22 23 24 |
# File 'lib/scout_apm/background_recorder.rb', line 22 def stop @thread.kill end |
#thread_func ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/scout_apm/background_recorder.rb', line 31 def thread_func while req = queue.pop begin logger.debug("recording in thread. Queue size: #{queue.size}") # For now, just proxy right back into the TrackedRequest object's record function req.record! rescue => e logger.warn("Error in BackgroundRecorder - #{e.} : #{e.backtrace}") end end end |