Class: HastCI::Heartbeat
- Inherits:
-
Object
- Object
- HastCI::Heartbeat
- Defined in:
- lib/hastci/heartbeat.rb
Instance Method Summary collapse
-
#initialize(api_client:, run_id:, error_collector: nil, interval: 15) ⇒ Heartbeat
constructor
A new instance of Heartbeat.
- #running? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(api_client:, run_id:, error_collector: nil, interval: 15) ⇒ Heartbeat
Returns a new instance of Heartbeat.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/hastci/heartbeat.rb', line 10 def initialize(api_client:, run_id:, error_collector: nil, interval: 15) @api_client = api_client @run_id = run_id @error_collector = error_collector @interval = interval @running = false @thread = nil @mutex = Mutex.new @stop_condition = ConditionVariable.new @consecutive_failures = 0 end |
Instance Method Details
#running? ⇒ Boolean
42 43 44 |
# File 'lib/hastci/heartbeat.rb', line 42 def running? @mutex.synchronize { @running } end |
#start ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/hastci/heartbeat.rb', line 22 def start @mutex.synchronize do return if @running @running = true @thread = Thread.new { run_loop } end end |
#stop ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/hastci/heartbeat.rb', line 31 def stop @mutex.synchronize do return unless @running @running = false @stop_condition.signal end @thread.join(SHUTDOWN_TIMEOUT) end |