class GemeraldBeanstalkStrategy::Tube

Constants

STATS_METHODS

Attributes that should be obtained via the tube’s stats. This list is used to dynamically create the attribute accessor methods.

Attributes

name[R]

The name of the tube represented by the object

Public Class Methods

new(tube_name, beanstalks) click to toggle source

Initialize a new GemeraldBeanstalkStrategy::Tube representing all tubes named ‘tube_name` in the given pool of `beanstalks`.

# File lib/bean_counter/strategies/gemerald_beanstalk_strategy/tube.rb, line 34
def initialize(tube_name, beanstalks)
  @name = tube_name
  @beanstalks = beanstalks
end

Public Instance Methods

exists?() click to toggle source

Returns a Boolean indicating whether or not the tube exists in the pool. @return [Boolean] Returns true if tube exists on any of the servers in the

pool, otherwise returns false.
# File lib/bean_counter/strategies/gemerald_beanstalk_strategy/tube.rb, line 23
def exists?
  tubes_in_pool = @beanstalks.inject([]) do |memo, beanstalk|
    memo.concat(beanstalk.tubes.keys)
  end
  tubes_in_pool.uniq!
  return tubes_in_pool.include?(@name)
end
to_hash() click to toggle source

Retrieves stats for the given ‘tube_name` from all known servers and merges numeric stats. Matches Beaneater’s treatment of a tube as a collective entity and not a per-server entity.

# File lib/bean_counter/strategies/gemerald_beanstalk_strategy/tube.rb, line 43
def to_hash
  return @beanstalks.inject({}) do |hash, beanstalk|
    next hash if (tube = beanstalk.tubes[name]).nil?
    next tube.stats if hash.empty?

    tube.stats.each do |stat, value|
      next unless value.is_a?(Numeric)
      hash[stat] += value
    end
    hash
  end
end