Class: NodeHeartbeat::RunHeartbeat

Inherits:
Base
  • Object
show all
Defined in:
lib/node_heartbeat/run_heartbeat.rb

Constant Summary collapse

SLEEP_TIME =

1 hour

60 * 60
ERROR_SLEEP_TIME =
5

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

call

Constructor Details

#initialize(bucket:) ⇒ RunHeartbeat

Returns a new instance of RunHeartbeat.



11
12
13
# File 'lib/node_heartbeat/run_heartbeat.rb', line 11

def initialize(bucket:)
  self.bucket = bucket
end

Instance Attribute Details

#bucketObject

Returns the value of attribute bucket.



6
7
8
# File 'lib/node_heartbeat/run_heartbeat.rb', line 6

def bucket
  @bucket
end

Instance Method Details

#callObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/node_heartbeat/run_heartbeat.rb', line 15

def call
  %w(INT TERM).each do |sig|
    begin
      trap sig do
        raise Interrupt
      end
    rescue ArgumentError
      puts "Signal #{sig} not supported"
    end
  end

  begin
    while true
      timeout = SLEEP_TIME
      begin
        BeatOnce.call(bucket: self.bucket)
      rescue => e
        puts "Warning: #{e.message}"
        timeout = ERROR_SLEEP_TIME
      end
      sleep timeout
    end
  rescue Interrupt
    puts 'Exiting'
  end
end