Module: Hutch::Config
- Defined in:
- lib/hutch/config.rb
Overview
Configuration settings, available everywhere
There are defaults, which can be overridden by ENV variables prefixed by HUTCH_
, and each of these can be overridden using the Config.set method.
Constant Summary collapse
- ALL_KEYS =
Set of all setting keys
@boolean_keys + @number_keys + @string_keys
Class Method Summary collapse
- .check_attr(attr) ⇒ Object
- .convert_value(attr, value) ⇒ Object
-
.default_config ⇒ Hash
Default settings.
- .define_methods ⇒ Object
-
.env_based_config ⇒ Hash
Override defaults with ENV variables which begin with
HUTCH_
. - .env_keys_configured ⇒ Array<Symbol>
- .get(attr) ⇒ Object (also: [])
- .initialize(params = {}) ⇒ Object
- .is_bool(attr) ⇒ Object
- .is_num(attr) ⇒ Object
- .key_for(attr) ⇒ Object
- .load_from_file(file) ⇒ Object
- .set(attr, value) ⇒ Object (also: []=)
- .to_bool(value) ⇒ Object
- .to_hash ⇒ Object
- .user_config ⇒ Object
Instance Method Summary collapse
-
#autoload_rails ⇒ Object
Should the current Rails app directory be required?.
-
#automatically_recover ⇒ Object
Bunny’s enable/disable network recovery.
-
#channel_prefetch ⇒ Object
The
basic.qos
prefetch value to use. -
#connection_timeout ⇒ Object
Bunny’s socket open timeout.
-
#consumer_pool_abort_on_exception ⇒ Object
Should Bunny’s consumer work pool threads abort on exception.
-
#consumer_pool_size ⇒ Object
Bunny consumer work pool size.
-
#consumer_tag_prefix ⇒ Object
Prefix displayed on the consumers tags.
-
#daemonise ⇒ Object
Should the Hutch runner process daemonise?.
-
#enable_http_api_use ⇒ Object
Should the RabbitMQ HTTP API be used?.
-
#force_publisher_confirms ⇒ Object
Enables publisher confirms, forces Hutch::Broker#wait_for_confirms for every publish.
-
#graceful_exit_timeout ⇒ Object
FIXME: DOCUMENT THIS.
- #group ⇒ Object
-
#heartbeat ⇒ Object
[RabbitMQ heartbeat timeout](rabbitmq.com/heartbeats.html).
-
#mq_api_host ⇒ Object
RabbitMQ HTTP API hostname.
-
#mq_api_port ⇒ Object
RabbitMQ HTTP API port.
-
#mq_api_ssl ⇒ Object
Should SSL be used for the RabbitMQ API?.
-
#mq_auth_mechanism ⇒ Object
RabbitMQ Auth Mechanism.
-
#mq_exchange ⇒ Object
RabbitMQ Exchange to use for publishing.
-
#mq_exchange_type ⇒ Object
RabbitMQ Exchange type to use for publishing.
-
#mq_host ⇒ Object
RabbitMQ hostname.
-
#mq_password ⇒ Object
RabbitMQ password.
-
#mq_port ⇒ Object
RabbitMQ port.
-
#mq_tls ⇒ Object
Should TLS be used?.
-
#mq_username ⇒ Object
RabbitMQ username to use.
-
#mq_verify_peer ⇒ Object
Should SSL certificate be verified?.
-
#mq_vhost ⇒ Object
RabbitMQ vhost to use.
-
#namespace ⇒ Object
A namespace to help group your queues.
-
#network_recovery_interval ⇒ Object
Bunny’s reconnect interval.
-
#publisher_confirms ⇒ Object
Should RabbitMQ publisher confirms be enabled?.
-
#read_timeout ⇒ Object
Bunny’s socket read timeout.
-
#uri ⇒ Object
RabbitMQ URI (takes precedence over MQ username, password, host, port and vhost settings).
-
#write_timeout ⇒ Object
Bunny’s socket write timeout.
Class Method Details
.check_attr(attr) ⇒ Object
250 251 252 253 254 |
# File 'lib/hutch/config.rb', line 250 def self.check_attr(attr) unless user_config.key?(attr) raise UnknownAttributeError, "#{attr.inspect} is not a valid config attribute" end end |
.convert_value(attr, value) ⇒ Object
270 271 272 273 274 275 276 277 |
# File 'lib/hutch/config.rb', line 270 def self.convert_value(attr, value) case attr when 'tracer' Kernel.const_get(value) else value end end |
.default_config ⇒ Hash
Default settings
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/hutch/config.rb', line 172 def self.default_config @settings_defaults.merge({ mq_exchange_options: {}, mq_tls_cert: nil, mq_tls_key: nil, mq_tls_ca_certificates: nil, uri: nil, log_level: Logger::INFO, client_logger: nil, require_paths: [], error_handlers: [Hutch::ErrorHandlers::Logger.new], # note that this is not a list, it is a chain of responsibility # that will fall back to "nack unconditionally" error_acknowledgements: [], setup_procs: [], consumer_groups: {}, tracer: Hutch::Tracers::NullTracer, namespace: nil, pidfile: nil, serializer: Hutch::Serializers::JSON }) end |
.define_methods ⇒ Object
291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/hutch/config.rb', line 291 def self.define_methods @config.keys.each do |key| define_singleton_method(key) do get(key) end define_singleton_method("#{key}=") do |val| set(key, val) end end end |
.env_based_config ⇒ Hash
Override defaults with ENV variables which begin with HUTCH_
198 199 200 201 202 203 204 |
# File 'lib/hutch/config.rb', line 198 def self.env_based_config env_keys_configured.each_with_object({}) {|attr, result| value = ENV[key_for(attr)] result[attr] = type_cast(attr, value) } end |
.env_keys_configured ⇒ Array<Symbol>
207 208 209 210 211 |
# File 'lib/hutch/config.rb', line 207 def self.env_keys_configured ALL_KEYS.each {|attr| check_attr(attr) } ALL_KEYS.select { |attr| ENV.key?(key_for(attr)) } end |
.get(attr) ⇒ Object Also known as: []
213 214 215 216 |
# File 'lib/hutch/config.rb', line 213 def self.get(attr) check_attr(attr.to_sym) user_config[attr.to_sym] end |
.initialize(params = {}) ⇒ Object
159 160 161 162 163 164 165 166 167 |
# File 'lib/hutch/config.rb', line 159 def self.initialize(params = {}) unless @config @config = default_config define_methods @config.merge!(env_based_config) end @config.merge!(params) @config end |
.is_bool(attr) ⇒ Object
223 224 225 |
# File 'lib/hutch/config.rb', line 223 def self.is_bool(attr) @boolean_keys.include?(attr) end |
.is_num(attr) ⇒ Object
236 237 238 |
# File 'lib/hutch/config.rb', line 236 def self.is_num(attr) @number_keys.include?(attr) end |
.key_for(attr) ⇒ Object
218 219 220 221 |
# File 'lib/hutch/config.rb', line 218 def self.key_for(attr) key = attr.to_s.gsub('.', '__').upcase "HUTCH_#{key}" end |
.load_from_file(file) ⇒ Object
264 265 266 267 268 |
# File 'lib/hutch/config.rb', line 264 def self.load_from_file(file) YAML.load(ERB.new(File.read(file)).result).each do |attr, value| Hutch::Config.send("#{attr}=", convert_value(attr, value)) end end |
.set(attr, value) ⇒ Object Also known as: []=
240 241 242 243 |
# File 'lib/hutch/config.rb', line 240 def self.set(attr, value) check_attr(attr.to_sym) user_config[attr.to_sym] = type_cast(attr, value) end |
.to_bool(value) ⇒ Object
227 228 229 230 231 232 233 234 |
# File 'lib/hutch/config.rb', line 227 def self.to_bool(value) case value when nil, false, '', /^(false|f|no|n|0)$/i false else true end end |
.to_hash ⇒ Object
260 261 262 |
# File 'lib/hutch/config.rb', line 260 def self.to_hash user_config end |
.user_config ⇒ Object
256 257 258 |
# File 'lib/hutch/config.rb', line 256 def self.user_config @config ||= initialize end |
Instance Method Details
#autoload_rails ⇒ Object
Should the current Rails app directory be required?
120 |
# File 'lib/hutch/config.rb', line 120 boolean_setting :autoload_rails, true |
#automatically_recover ⇒ Object
Bunny’s enable/disable network recovery
99 |
# File 'lib/hutch/config.rb', line 99 boolean_setting :automatically_recover, true |
#channel_prefetch ⇒ Object
The basic.qos
prefetch value to use.
Default: ‘0`, no limit. See Bunny and RabbitMQ documentation.
87 |
# File 'lib/hutch/config.rb', line 87 number_setting :channel_prefetch, 0 |
#connection_timeout ⇒ Object
Bunny’s socket open timeout
90 |
# File 'lib/hutch/config.rb', line 90 number_setting :connection_timeout, 11 |
#consumer_pool_abort_on_exception ⇒ Object
Should Bunny’s consumer work pool threads abort on exception.
The option is ignored on JRuby.
146 |
# File 'lib/hutch/config.rb', line 146 boolean_setting :consumer_pool_abort_on_exception, false |
#consumer_pool_size ⇒ Object
Bunny consumer work pool size
108 |
# File 'lib/hutch/config.rb', line 108 number_setting :consumer_pool_size, 1 |
#consumer_tag_prefix ⇒ Object
Prefix displayed on the consumers tags.
149 |
# File 'lib/hutch/config.rb', line 149 string_setting :consumer_tag_prefix, 'hutch' |
#daemonise ⇒ Object
Should the Hutch runner process daemonise?
The option is ignored on JRuby.
125 |
# File 'lib/hutch/config.rb', line 125 boolean_setting :daemonise, false |
#enable_http_api_use ⇒ Object
Should the RabbitMQ HTTP API be used?
141 |
# File 'lib/hutch/config.rb', line 141 boolean_setting :enable_http_api_use, true |
#force_publisher_confirms ⇒ Object
Enables publisher confirms, forces Hutch::Broker#wait_for_confirms for every publish.
**This is the safest option which also offers the lowest throughput**.
138 |
# File 'lib/hutch/config.rb', line 138 boolean_setting :force_publisher_confirms, false |
#graceful_exit_timeout ⇒ Object
FIXME: DOCUMENT THIS
105 |
# File 'lib/hutch/config.rb', line 105 number_setting :graceful_exit_timeout, 11 |
#group ⇒ Object
154 |
# File 'lib/hutch/config.rb', line 154 string_setting :group, '' |
#heartbeat ⇒ Object
[RabbitMQ heartbeat timeout](rabbitmq.com/heartbeats.html)
82 |
# File 'lib/hutch/config.rb', line 82 number_setting :heartbeat, 30 |
#mq_api_host ⇒ Object
RabbitMQ HTTP API hostname
73 |
# File 'lib/hutch/config.rb', line 73 string_setting :mq_api_host, '127.0.0.1' |
#mq_api_port ⇒ Object
RabbitMQ HTTP API port
79 |
# File 'lib/hutch/config.rb', line 79 number_setting :mq_api_port, 15672 |
#mq_api_ssl ⇒ Object
Should SSL be used for the RabbitMQ API?
117 |
# File 'lib/hutch/config.rb', line 117 boolean_setting :mq_api_ssl, false |
#mq_auth_mechanism ⇒ Object
RabbitMQ Auth Mechanism
67 |
# File 'lib/hutch/config.rb', line 67 string_setting :mq_auth_mechanism, 'PLAIN' |
#mq_exchange ⇒ Object
RabbitMQ Exchange to use for publishing
50 |
# File 'lib/hutch/config.rb', line 50 string_setting :mq_exchange, 'hutch' |
#mq_exchange_type ⇒ Object
RabbitMQ Exchange type to use for publishing
53 |
# File 'lib/hutch/config.rb', line 53 string_setting :mq_exchange_type, 'topic' |
#mq_host ⇒ Object
RabbitMQ hostname
47 |
# File 'lib/hutch/config.rb', line 47 string_setting :mq_host, '127.0.0.1' |
#mq_password ⇒ Object
RabbitMQ password
64 |
# File 'lib/hutch/config.rb', line 64 string_setting :mq_password, 'guest' |
#mq_port ⇒ Object
RabbitMQ port
76 |
# File 'lib/hutch/config.rb', line 76 number_setting :mq_port, 5672 |
#mq_tls ⇒ Object
Should TLS be used?
111 |
# File 'lib/hutch/config.rb', line 111 boolean_setting :mq_tls, false |
#mq_username ⇒ Object
RabbitMQ username to use.
As of RabbitMQ 3.3.0, guest
can only can connect from localhost.
61 |
# File 'lib/hutch/config.rb', line 61 string_setting :mq_username, 'guest' |
#mq_verify_peer ⇒ Object
Should SSL certificate be verified?
114 |
# File 'lib/hutch/config.rb', line 114 boolean_setting :mq_verify_peer, true |
#mq_vhost ⇒ Object
RabbitMQ vhost to use
56 |
# File 'lib/hutch/config.rb', line 56 string_setting :mq_vhost, '/' |
#namespace ⇒ Object
A namespace to help group your queues
152 |
# File 'lib/hutch/config.rb', line 152 string_setting :namespace, nil |
#network_recovery_interval ⇒ Object
Bunny’s reconnect interval
102 |
# File 'lib/hutch/config.rb', line 102 number_setting :network_recovery_interval, 1 |
#publisher_confirms ⇒ Object
Should RabbitMQ publisher confirms be enabled?
Leaves it up to the app how they are tracked (e.g. using Hutch::Broker#confirm_select callback or Hutch::Broker#wait_for_confirms)
131 |
# File 'lib/hutch/config.rb', line 131 boolean_setting :publisher_confirms, false |
#read_timeout ⇒ Object
Bunny’s socket read timeout
93 |
# File 'lib/hutch/config.rb', line 93 number_setting :read_timeout, 11 |
#uri ⇒ Object
RabbitMQ URI (takes precedence over MQ username, password, host, port and vhost settings)
70 |
# File 'lib/hutch/config.rb', line 70 string_setting :uri, nil |
#write_timeout ⇒ Object
Bunny’s socket write timeout
96 |
# File 'lib/hutch/config.rb', line 96 number_setting :write_timeout, 11 |