Class: BeanCounter::Strategy::GemeraldBeanstalkStrategy::Tube
- Inherits:
-
Object
- Object
- BeanCounter::Strategy::GemeraldBeanstalkStrategy::Tube
- Defined in:
- lib/bean_counter/strategies/gemerald_beanstalk_strategy/tube.rb
Constant Summary collapse
- STATS_METHODS =
Attributes that should be obtained via the tube's stats. This list is used to dynamically create the attribute accessor methods.
%w[ cmd-delete cmd-pause-tube current-jobs-buried current-jobs-delayed current-jobs-ready current-jobs-reserved current-jobs-urgent current-using current-waiting current-watching pause pause-time-left total-jobs ]
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
The name of the tube represented by the object.
Instance Method Summary collapse
-
#exists? ⇒ Boolean
Returns a Boolean indicating whether or not the tube exists in the pool.
-
#initialize(tube_name, beanstalks) ⇒ Tube
constructor
Initialize a new GemeraldBeanstalkStrategy::Tube representing all tubes named
tube_name
in the given pool ofbeanstalks
. -
#to_hash ⇒ Object
Retrieves stats for the given
tube_name
from all known servers and merges numeric stats.
Constructor Details
#initialize(tube_name, beanstalks) ⇒ Tube
Initialize a new GemeraldBeanstalkStrategy::Tube representing all tubes
named tube_name
in the given pool of beanstalks
.
34 35 36 37 |
# File 'lib/bean_counter/strategies/gemerald_beanstalk_strategy/tube.rb', line 34 def initialize(tube_name, beanstalks) @name = tube_name @beanstalks = beanstalks end |
Instance Attribute Details
#name ⇒ Object (readonly)
The name of the tube represented by the object
4 5 6 |
# File 'lib/bean_counter/strategies/gemerald_beanstalk_strategy/tube.rb', line 4 def name @name end |
Instance Method Details
#exists? ⇒ Boolean
Returns a Boolean indicating whether or not the tube exists in the pool.
23 24 25 26 27 28 29 |
# 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 ⇒ Object
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.
43 44 45 46 47 48 49 50 51 52 53 54 |
# 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 |