Module: BeanCounter
- Defined in:
- lib/bean_counter/core.rb,
lib/bean_counter/version.rb
Defined Under Namespace
Modules: SpecMatchers, TestAssertions Classes: EnqueuedExpectation, Strategy, TubeExpectation
Constant Summary collapse
- DEFAULT_STRATEGY =
Use StalkClimberStrategy by default because it works with standard Beanstalkd
:'BeanCounter::Strategy::StalkClimberStrategy'
- VERSION =
BeanCounter version number
'0.1.0'
Class Method Summary collapse
-
.beanstalkd_url ⇒ Array<String>
Returns an Array of parsed Beanstalkd URLs.
-
.beanstalkd_url=(value) ⇒ Object
Sets the Beanstalkd server URLs to be used by BeanCounter.
-
.default_strategy ⇒ BeanCounter::Strategy
Returns a previously materialized strategy or materializes a new default strategy for use.
-
.reset!(tube_name = nil) ⇒ Boolean
Uses strategy to delete all jobs from the beanstalkd pool or from the tube specified by
tube_name
. -
.strategies ⇒ Array<BeanCounter::Strategy>
Returns a list of known subclasses of BeanCounter::Strategy.
-
.strategy ⇒ BeanCounter::Strategy
Returns a previously materialized strategy or instantiates a new instance of the default strategy.
-
.strategy=(strategy_identifier) ⇒ Object
Sets the strategy that BeanCounter should use when interacting with Beanstalkd.
Class Method Details
.beanstalkd_url ⇒ Array<String>
Returns an Array of parsed Beanstalkd URLs.
Server URLs provided via the environment variable BEANSTALKD_URL
are given
precedence. When setting beanstalkd_url from the environment, urls are
expected in a comma separated list. If ENV['BEANSTALKD_URL']
is not set,
the BeanCounter.beanstalkd_url instance variable is checked and parsed next.
Finally, if the BeanCounter.beanstalkd_url instance variable has not been
set, the configuration for Beaneater is checked and parsed. If no
beanstalkd_url can be determined a RuntimeError is raised.
Beanstalkd URLs can be provided in any of three supported formats shown in
in the examples below.
In short, a host is the only required component. If no port is provided, the default beanstalkd port of 11300 is assumed. If a URI scheme other than beanstalk is provided the strategy in use will likely raise an error.
58 59 60 61 62 63 64 |
# File 'lib/bean_counter/core.rb', line 58 def self.beanstalkd_url @hosts_from_env = ENV['BEANSTALKD_URL'] @hosts_from_env = @hosts_from_env.split(',').map!(&:strip) unless @hosts_from_env.nil? beanstalkd_url = @hosts_from_env || @beanstalkd_url || Beaneater.configuration.beanstalkd_url raise 'Could not determine beanstalkd url' if beanstalkd_url.to_s == '' return beanstalkd_url.is_a?(Array) ? beanstalkd_url : [beanstalkd_url] end |
.beanstalkd_url=(value) ⇒ Object
Sets the Beanstalkd server URLs to be used by BeanCounter.
10 11 12 |
# File 'lib/bean_counter/core.rb', line 10 def self.beanstalkd_url=(value) @beanstalkd_url = value end |
.default_strategy ⇒ BeanCounter::Strategy
Returns a previously materialized strategy or materializes a new default strategy for use.
See BeanCounter::Strategy.materialize_strategy for more information on the materialization process.
75 76 77 |
# File 'lib/bean_counter/core.rb', line 75 def self.default_strategy return @default_strategy ||= BeanCounter::Strategy.materialize_strategy(DEFAULT_STRATEGY) end |
.reset!(tube_name = nil) ⇒ Boolean
Uses strategy to delete all jobs from the beanstalkd pool or from the tube
specified by tube_name
.
It should be noted that jobs that are reserved can only be deleted by the reserving connection and thus cannot be deleted via this method. As such, care may need to be taken to ensure that jobs are not left in a reserved state.
92 93 94 95 96 97 98 99 |
# File 'lib/bean_counter/core.rb', line 92 def self.reset!(tube_name = nil) partial_failure = false strategy.jobs.each do |job| success = strategy.delete_job(job) if tube_name.nil? || strategy.job_matches?(job, :tube => tube_name) partial_failure ||= success end return !partial_failure end |
.strategies ⇒ Array<BeanCounter::Strategy>
Returns a list of known subclasses of BeanCounter::Strategy. Typically this list represents the strategies available for interacting with Beanstalkd.
107 108 109 |
# File 'lib/bean_counter/core.rb', line 107 def self.strategies return BeanCounter::Strategy.strategies end |
.strategy ⇒ BeanCounter::Strategy
Returns a previously materialized strategy or instantiates a new instance of the default strategy. If no previous strategy exists, a new instance of the default strategy is instantiated and returned.
137 138 139 |
# File 'lib/bean_counter/core.rb', line 137 def self.strategy return @strategy ||= default_strategy.new end |
.strategy=(strategy_identifier) ⇒ Object
Sets the strategy that BeanCounter should use when interacting with Beanstalkd.
The value provided for strategy_identifier
will be used to
materialize an instance of the matching strategy class. If the provided
strategy_identifier
is nil, any existing strategy will be cleared and
the next call to BeanCounter.strategy will use the default strategy.
122 123 124 125 126 127 128 |
# File 'lib/bean_counter/core.rb', line 122 def self.strategy=(strategy_identifier) if strategy_identifier.nil? @strategy = nil else @strategy = BeanCounter::Strategy.materialize_strategy(strategy_identifier).new end end |