Sha256: f418cb815a5dbadc04cf9b064eeef5ab723d41b944553d11d8d783eb8d4eb84e

Contents?: true

Size: 779 Bytes

Versions: 3

Compression:

Stored size: 779 Bytes

Contents

require 'net/http'

module BigBrother
  class Node
    attr_reader :address, :port, :path

    def initialize(address, port, path)
      @address = address
      @port = port
      @path = path
      @weight = nil
    end

    def invalidate_weight!
      @weight = nil
    end

    def monitor(cluster)
      new_weight = _determine_weight(cluster)
      return unless cluster.monitored?
      if new_weight != @weight
        BigBrother.ipvs.edit_node(cluster.fwmark, address, new_weight)
        @weight = new_weight
      end
    end

    def _determine_weight(cluster)
      if cluster.up_file_exists?
        100
      elsif cluster.down_file_exists?
        0
      else
        BigBrother::HealthFetcher.current_health(@address, @port, @path)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
big_brother-0.4.1 lib/big_brother/node.rb
big_brother-0.4.0 lib/big_brother/node.rb
big_brother-0.3.1 lib/big_brother/node.rb