Class: Contrast::Agent::ThreadWatcher
- Includes:
- Components::Interface
- Defined in:
- lib/contrast/agent/thread_watcher.rb
Overview
This class used to ensure that our worker threads are running in multi-process environments
Instance Attribute Summary collapse
-
#heartbeat ⇒ Object
readonly
Returns the value of attribute heartbeat.
Instance Method Summary collapse
- #ensure_running? ⇒ Boolean
-
#initialize ⇒ ThreadWatcher
constructor
A new instance of ThreadWatcher.
- #startup! ⇒ Object
Methods included from Components::Interface
Constructor Details
#initialize ⇒ ThreadWatcher
Returns a new instance of ThreadWatcher.
16 17 18 19 |
# File 'lib/contrast/agent/thread_watcher.rb', line 16 def initialize @pids = {} @heartbeat = Contrast::Agent::ServiceHeartbeat.new end |
Instance Attribute Details
#heartbeat ⇒ Object (readonly)
Returns the value of attribute heartbeat.
14 15 16 |
# File 'lib/contrast/agent/thread_watcher.rb', line 14 def heartbeat @heartbeat end |
Instance Method Details
#ensure_running? ⇒ Boolean
41 42 43 44 45 46 |
# File 'lib/contrast/agent/thread_watcher.rb', line 41 def ensure_running? return if @pids[Process.pid] == true logger.debug('ThreadWatcher - threads not running') startup! end |
#startup! ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/contrast/agent/thread_watcher.rb', line 21 def startup! unless heartbeat.running? logger.debug('Attempting to start heartbeat thread') heartbeat.start_thread! end heartbeat_result = heartbeat.running? logger.debug('Heartbeat thread status', alive: heartbeat_result) unless Contrast::Agent.messaging_queue.running? logger.debug('Attempting to start messaging queue thread') Contrast::Agent.messaging_queue.start_thread! end messaging_result = Contrast::Agent.messaging_queue.running? logger.debug('Messaging thread status', alive: messaging_result) logger.debug('ThreadWatcher started threads') @pids[Process.pid] = messaging_result && heartbeat_result end |