1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
require 'thread' unless defined?(Mutex)
%w(version configuration errors connection tube job stats).each do |f|
require "beaneater/#{f}"
end
class Beaneater
# @!attribute connection
# @return <Beaneater::Connection> returns the associated connection object
attr_reader :connection
# Initialize new instance of Beaneater
#
# @param [String] address in the form "host:port"
# @example
# Beaneater.new('127.0.0.1:11300')
#
# ENV['BEANSTALKD_URL'] = '127.0.0.1:11300'
# @b = Beaneater.new
# @b.connection.host # => '127.0.0.1'
# @b.connection.port # => '11300'
#
def initialize(address=nil)
@connection = Connection.new(address)
end
# Returns Beaneater::Tubes object for accessing tube related functions.
#
# @return [Beaneater::Tubes] tubes object
# @api public
def tubes
@tubes ||= Beaneater::Tubes.new(self)
end
# Returns Beaneater::Jobs object for accessing job related functions.
#
# @return [Beaneater::Jobs] jobs object
# @api public
def jobs
@jobs ||= Beaneater::Jobs.new(self)
end
# Returns Beaneater::Stats object for accessing beanstalk stats.
#
# @return [Beaneater::Stats] stats object
# @api public
def stats
@stats ||= Stats.new(self)
end
# Closes the related connection
#
# @example
# @beaneater_instance.close
#
def close
connection.close if connection
end
protected
class << self
# Yields a configuration block
#
# @example
# Beaneater.configure do |config|
# config.job_parser = lamda { |body| Yaml.load(body)}
# end
#
def configure(&block)
yield(configuration) if block_given?
configuration
end
# Returns the configuration options set for Backburner
#
# @example
# Beaneater.configuration.default_put_ttr => 120
#
def configuration
@_configuration ||= Configuration.new
end
end
end # Beaneater
|