Sha256: a3636805383bd3f1abfd5c19354089c2e85815f45241181a625540c0bf790215

Contents?: true

Size: 872 Bytes

Versions: 2

Compression:

Stored size: 872 Bytes

Contents

module Refinery #:nodoc:
  # A heartbeat publisher that indicates a server is alive.
  class Heartbeat
    include Refinery::Loggable
    include Refinery::Configurable
    include Refinery::Queueable
    include Refinery::Utilities
    
    # Initialize the heartbeat for the given server.
    def initialize(server)
      queue_prefix = config['prefix'] || ''
      @server = server
      @thread = Thread.new do
        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
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
aeden-refinery-0.10.6 lib/refinery/heartbeat.rb
refinery-0.10.6 lib/refinery/heartbeat.rb