Class: DistribCore::Leader::Watchdog
- Inherits:
-
Object
- Object
- DistribCore::Leader::Watchdog
- Defined in:
- lib/distrib_core/leader/watchdog.rb
Overview
A watchdog to observe the state of queue. A thread running on the background that keeps checking if there are tests to run. It closes the connection between Leader and Workers when the queues are empty. A thread watching over presence of the entries on the queue and lease timeouts. Stops the DistribCore::Leader by stopping its DRb exposed service.
Instance Method Summary collapse
-
#failed? ⇒ TrueClass, FalseClass
‘true` when watchdog encountered an error.
-
#initialize(queue) ⇒ Watchdog
constructor
A new instance of Watchdog.
-
#start ⇒ Object
rubocop:disable Metrics/MethodLength, Metrics/AbcSize.
Constructor Details
#initialize(queue) ⇒ Watchdog
Returns a new instance of Watchdog.
13 14 15 16 17 |
# File 'lib/distrib_core/leader/watchdog.rb', line 13 def initialize(queue) @queue = queue @failed = false @logger = DistribCore.configuration.broadcaster end |
Instance Method Details
#failed? ⇒ TrueClass, FalseClass
Returns ‘true` when watchdog encountered an error.
52 53 54 |
# File 'lib/distrib_core/leader/watchdog.rb', line 52 def failed? @failed end |
#start ⇒ Object
rubocop:disable Metrics/MethodLength, Metrics/AbcSize
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/distrib_core/leader/watchdog.rb', line 19 def start # rubocop:disable Metrics/MethodLength, Metrics/AbcSize Thread.new do loop do if ::DistribCore::ReceivedSignals.any? logger.warn ::DistribCore::ReceivedSignals. DRb.current_server.stop_service break end handle_timed_out_tests if queue.empty? # no more tests left logger.info 'Queue is empty. Stopping.' DRb.current_server.stop_service break end timeout_error = handle_workers_timeout if timeout_error logger.error timeout_error logger.info not_executed_tests_after_timeout_report @failed = true DRb.current_server.stop_service break end Kernel.sleep(1) end end end |