Class: Refinery::Heartbeat

Inherits:
Object
  • Object
show all
Includes:
Configurable, Loggable, Queueable, Utilities
Defined in:
lib/refinery/heartbeat.rb

Overview

A heartbeat publisher that indicates a server is alive.

Instance Method Summary collapse

Methods included from Utilities

#camelize, #decode_message, #encode_message, #host_info

Methods included from Queueable

#queue, #with_queue

Methods included from Configurable

#config, #config=

Methods included from Loggable

#logger

Constructor Details

#initialize(server) ⇒ Heartbeat

Initialize the heartbeat for the given server.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/refinery/heartbeat.rb', line 10

def initialize(server)
  queue_prefix = config['prefix'] || ''
  @server = server
  @thread = Thread.new do
    if defined?(java.lang.Thread)
      java.lang.Thread.current_thread.name = 'Heartbeat'
    end
    
    loop do
      with_queue("#{queue_prefix}heartbeat") do |heartbeat_queue|
        logger.debug "Send heartbeat"
        message = {
          'host_info' => host_info,
          'timestamp' => Time.now.utc,
          'running_daemons' => @server.daemons.length
        }
        heartbeat_queue.send_message(Base64.encode64(message.to_json))
        sleep(60)
      end
    end
  end
end