Class: ScoutApm::BackgroundRecorder
- Inherits:
-
Object
- Object
- ScoutApm::BackgroundRecorder
- Defined in:
- lib/scout_apm/background_recorder.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Instance Method Summary collapse
-
#initialize(context) ⇒ BackgroundRecorder
constructor
A new instance of BackgroundRecorder.
- #logger ⇒ Object
- #record!(request) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #thread_func ⇒ Object
Constructor Details
#initialize(context) ⇒ BackgroundRecorder
Returns a new instance of BackgroundRecorder.
12 13 14 15 |
# File 'lib/scout_apm/background_recorder.rb', line 12 def initialize(context) @context = context @queue = Queue.new end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
7 8 9 |
# File 'lib/scout_apm/background_recorder.rb', line 7 def context @context end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
9 10 11 |
# File 'lib/scout_apm/background_recorder.rb', line 9 def queue @queue end |
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
10 11 12 |
# File 'lib/scout_apm/background_recorder.rb', line 10 def thread @thread end |
Instance Method Details
#logger ⇒ Object
17 18 19 |
# File 'lib/scout_apm/background_recorder.rb', line 17 def logger context.logger end |
#record!(request) ⇒ Object
31 32 33 34 |
# File 'lib/scout_apm/background_recorder.rb', line 31 def record!(request) start unless @thread.alive? @queue.push(request) end |
#start ⇒ Object
21 22 23 24 25 |
# File 'lib/scout_apm/background_recorder.rb', line 21 def start logger.info("Starting BackgroundRecorder") @thread = Thread.new(&method(:thread_func)) self end |
#stop ⇒ Object
27 28 29 |
# File 'lib/scout_apm/background_recorder.rb', line 27 def stop @thread.kill end |
#thread_func ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/scout_apm/background_recorder.rb', line 36 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 |