Sha256: 47f0108dab72d678e73abcbfa3ac850ef287ad00bf6278a46d0e4e18410cf5fd

Contents?: true

Size: 931 Bytes

Versions: 4

Compression:

Stored size: 931 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)
      @server = server
      @thread = Thread.new(queue('heartbeat')) do |heartbeat_queue|
        loop do
          begin
            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)
          rescue Exception => e
            logger.error "Error sending heartbeat: #{e.message}"
            sleep(30)
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
aeden-refinery-0.9.11 lib/refinery/heartbeat.rb
aeden-refinery-0.9.12 lib/refinery/heartbeat.rb
refinery-0.9.11 lib/refinery/heartbeat.rb
refinery-0.9.12 lib/refinery/heartbeat.rb