Class: BeanCounter::Strategy::StalkClimberStrategy
- Inherits:
-
BeanCounter::Strategy
- Object
- BeanCounter::Strategy
- BeanCounter::Strategy::StalkClimberStrategy
- Extended by:
- Forwardable
- Defined in:
- lib/bean_counter/strategies/stalk_climber_strategy.rb
Constant Summary collapse
- STATS_METHOD_NAMES =
Index of what method should be called to retrieve each stat
begin attrs = ( BeanCounter::Strategy::MATCHABLE_JOB_ATTRIBUTES + BeanCounter::Strategy::MATCHABLE_TUBE_ATTRIBUTES ).map!(&:to_sym).uniq.sort method_names = attrs.map {|method| method.to_s.gsub(/-/, '_').to_sym } attr_methods = Hash[attrs.zip(method_names)] attr_methods[:pause] = :pause_time attr_methods end
- TEST_TUBE =
Default tube used by StalkClimber when probing the beanstalkd pool
'bean_counter_stalk_climber_test'
Constants inherited from BeanCounter::Strategy
MATCHABLE_JOB_ATTRIBUTES, MATCHABLE_TUBE_ATTRIBUTES
Instance Attribute Summary collapse
-
#test_tube ⇒ Object
writeonly
The tube that will be used by StalkClimber when probing the beanstalkd pool.
Instance Method Summary collapse
-
#collect_new_jobs ⇒ Object
:call-seq: collect_new_jobs { block } => Array.
-
#delete_job(job) ⇒ Object
:call-seq: delete_job(job) => Boolean.
-
#job_matches?(job, opts = {}) ⇒ Boolean
:call-seq: job_matches?(job, options => => Numeric,Proc,Range,Regexp,String) => Boolean.
-
#pretty_print_job(job) ⇒ Object
:call-seq: pretty_print_job(job) => String.
-
#pretty_print_tube(tube) ⇒ Object
:call-seq: pretty_print_tube(tube) => String.
-
#tube_matches?(tube, opts = {}) ⇒ Boolean
:call-seq: tube_matches?(tube, options => => Numeric,Proc,Range,Regexp,String) => Boolean.
Methods inherited from BeanCounter::Strategy
inherited, #jobs, known_strategy?, materialize_strategy, strategies, #tubes
Instance Attribute Details
#test_tube=(value) ⇒ Object
The tube that will be used by StalkClimber when probing the beanstalkd pool. Uses TEST_TUBE if no value provided.
24 25 26 |
# File 'lib/bean_counter/strategies/stalk_climber_strategy.rb', line 24 def test_tube=(value) @test_tube = value end |
Instance Method Details
#collect_new_jobs ⇒ Object
:call-seq:
collect_new_jobs { block } => Array[StalkClimber::Job]
Collects all jobs enqueued during the execution of the provided block. Returns an Array of StalkClimber::Job.
Fulfills Strategy#collect_new_jobs contract. See Strategy#collect_new_jobs for more information.
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/bean_counter/strategies/stalk_climber_strategy.rb', line 37 def collect_new_jobs raise ArgumentError, 'Block required' unless block_given? min_ids = climber.max_job_ids yield max_ids = climber.max_job_ids new_jobs = [] min_ids.each do |connection, min_id| testable_ids = (min_id..max_ids[connection]).to_a new_jobs.concat(connection.fetch_jobs(testable_ids).compact) end return new_jobs end |
#delete_job(job) ⇒ Object
:call-seq:
delete_job(job) => Boolean
Attempts to delete the given StalkClimber::Job job. Returns true if deletion succeeds or if job does not exist. Returns false if job could not be deleted (typically due to it being reserved by another connection).
Fulfills Strategy#delete_job contract. See Strategy#delete_job for more information.
61 62 63 64 65 66 |
# File 'lib/bean_counter/strategies/stalk_climber_strategy.rb', line 61 def delete_job(job) job.delete return true rescue Beaneater::NotFoundError return job.exists? ? false : true end |
#job_matches?(job, opts = {}) ⇒ Boolean
:call-seq:
job_matches?(job, => {Symbol,String => Numeric,Proc,Range,Regexp,String}) => Boolean
Returns a boolean indicating whether or not the provided StalkClimber::Job job matches the given Hash of +options.
Fulfills Strategy#job_matches? contract. See Strategy#job_matches? for more information.
77 78 79 |
# File 'lib/bean_counter/strategies/stalk_climber_strategy.rb', line 77 def job_matches?(job, opts = {}) return matcher(MATCHABLE_JOB_ATTRIBUTES, job, opts) end |
#pretty_print_job(job) ⇒ Object
:call-seq:
pretty_print_job(job) => String
Returns a String representation of the StalkClimber::Job job in a pretty, human readable format.
Fulfills Strategy#pretty_print_job contract. See Strategy#pretty_print_job for more information.
90 91 92 |
# File 'lib/bean_counter/strategies/stalk_climber_strategy.rb', line 90 def pretty_print_job(job) return job.to_h.to_s end |
#pretty_print_tube(tube) ⇒ Object
:call-seq:
pretty_print_tube(tube) => String
Returns a String representation of tube in a pretty, human readable format.
Fulfills Strategy#pretty_print_tube contract. See Strategy#pretty_print_tube for more information.
102 103 104 |
# File 'lib/bean_counter/strategies/stalk_climber_strategy.rb', line 102 def pretty_print_tube(tube) return tube.to_h.to_s end |
#tube_matches?(tube, opts = {}) ⇒ Boolean
:call-seq:
tube_matches?(tube, => {Symbol,String => Numeric,Proc,Range,Regexp,String}) => Boolean
Returns a boolean indicating whether or not the provided StalkClimber tube matches the given Hash of +options.
Fulfills Strategy#tube_matches? contract. See Strategy#tube_matches? for more information.
115 116 117 |
# File 'lib/bean_counter/strategies/stalk_climber_strategy.rb', line 115 def tube_matches?(tube, opts = {}) return matcher(MATCHABLE_TUBE_ATTRIBUTES, tube, opts) end |