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_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.
-
#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
246 247 248 249 250 |
# File 'lib/hutch/config.rb', line 246 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
266 267 268 269 270 271 272 273 |
# File 'lib/hutch/config.rb', line 266 def self.convert_value(attr, value) case attr when 'tracer' Kernel.const_get(value) else value end end |
.default_config ⇒ Hash
Default settings
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/hutch/config.rb', line 166 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
275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/hutch/config.rb', line 275 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_
192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/hutch/config.rb', line 192 def self.env_based_config env_keys_configured.each_with_object({}) {|attr, result| value = ENV[key_for(attr)] case when is_bool(attr) || value == 'false' result[attr] = to_bool(value) when is_num(attr) result[attr] = value.to_i else result[attr] = value end } end |
.env_keys_configured ⇒ Array<Symbol>
208 209 210 211 212 |
# File 'lib/hutch/config.rb', line 208 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: []
214 215 216 217 |
# File 'lib/hutch/config.rb', line 214 def self.get(attr) check_attr(attr.to_sym) user_config[attr.to_sym] end |
.initialize(params = {}) ⇒ Object
153 154 155 156 157 158 159 160 161 |
# File 'lib/hutch/config.rb', line 153 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
224 225 226 |
# File 'lib/hutch/config.rb', line 224 def self.is_bool(attr) @boolean_keys.include?(attr) end |
.is_num(attr) ⇒ Object
232 233 234 |
# File 'lib/hutch/config.rb', line 232 def self.is_num(attr) @number_keys.include?(attr) end |
.key_for(attr) ⇒ Object
219 220 221 222 |
# File 'lib/hutch/config.rb', line 219 def self.key_for(attr) key = attr.to_s.gsub('.', '__').upcase "HUTCH_#{key}" end |
.load_from_file(file) ⇒ Object
260 261 262 263 264 |
# File 'lib/hutch/config.rb', line 260 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: []=
236 237 238 239 |
# File 'lib/hutch/config.rb', line 236 def self.set(attr, value) check_attr(attr.to_sym) user_config[attr.to_sym] = value end |
.to_bool(value) ⇒ Object
228 229 230 |
# File 'lib/hutch/config.rb', line 228 def self.to_bool(value) !(value.nil? || value == '' || value =~ /^(false|f|no|n|0)$/i || value == false) end |
.to_hash ⇒ Object
256 257 258 |
# File 'lib/hutch/config.rb', line 256 def self.to_hash user_config end |
.user_config ⇒ Object
252 253 254 |
# File 'lib/hutch/config.rb', line 252 def self.user_config @config ||= initialize end |
Instance Method Details
#autoload_rails ⇒ Object
Should the current Rails app directory be required?
117 |
# File 'lib/hutch/config.rb', line 117 boolean_setting :autoload_rails, true |
#automatically_recover ⇒ Object
Bunny’s enable/disable network recovery
96 |
# File 'lib/hutch/config.rb', line 96 boolean_setting :automatically_recover, true |
#channel_prefetch ⇒ Object
The basic.qos
prefetch value to use.
Default: ‘0`, no limit. See Bunny and RabbitMQ documentation.
84 |
# File 'lib/hutch/config.rb', line 84 number_setting :channel_prefetch, 0 |
#connection_timeout ⇒ Object
Bunny’s socket open timeout
87 |
# File 'lib/hutch/config.rb', line 87 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.
143 |
# File 'lib/hutch/config.rb', line 143 boolean_setting :consumer_pool_abort_on_exception, false |
#consumer_pool_size ⇒ Object
Bunny consumer work pool size
105 |
# File 'lib/hutch/config.rb', line 105 number_setting :consumer_pool_size, 1 |
#consumer_tag_prefix ⇒ Object
Prefix displayed on the consumers tags.
146 |
# File 'lib/hutch/config.rb', line 146 string_setting :consumer_tag_prefix, 'hutch' |
#daemonise ⇒ Object
Should the Hutch runner process daemonise?
The option is ignored on JRuby.
122 |
# File 'lib/hutch/config.rb', line 122 boolean_setting :daemonise, false |
#enable_http_api_use ⇒ Object
Should the RabbitMQ HTTP API be used?
138 |
# File 'lib/hutch/config.rb', line 138 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**.
135 |
# File 'lib/hutch/config.rb', line 135 boolean_setting :force_publisher_confirms, false |
#graceful_exit_timeout ⇒ Object
FIXME: DOCUMENT THIS
102 |
# File 'lib/hutch/config.rb', line 102 number_setting :graceful_exit_timeout, 11 |
#group ⇒ Object
148 |
# File 'lib/hutch/config.rb', line 148 string_setting :group, '' |
#heartbeat ⇒ Object
[RabbitMQ heartbeat timeout](rabbitmq.com/heartbeats.html)
79 |
# File 'lib/hutch/config.rb', line 79 number_setting :heartbeat, 30 |
#mq_api_host ⇒ Object
RabbitMQ HTTP API hostname
70 |
# File 'lib/hutch/config.rb', line 70 string_setting :mq_api_host, '127.0.0.1' |
#mq_api_port ⇒ Object
RabbitMQ HTTP API port
76 |
# File 'lib/hutch/config.rb', line 76 number_setting :mq_api_port, 15672 |
#mq_api_ssl ⇒ Object
Should SSL be used for the RabbitMQ API?
114 |
# File 'lib/hutch/config.rb', line 114 boolean_setting :mq_api_ssl, false |
#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
73 |
# File 'lib/hutch/config.rb', line 73 number_setting :mq_port, 5672 |
#mq_tls ⇒ Object
Should TLS be used?
108 |
# File 'lib/hutch/config.rb', line 108 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?
111 |
# File 'lib/hutch/config.rb', line 111 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, '/' |
#network_recovery_interval ⇒ Object
Bunny’s reconnect interval
99 |
# File 'lib/hutch/config.rb', line 99 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)
128 |
# File 'lib/hutch/config.rb', line 128 boolean_setting :publisher_confirms, false |
#read_timeout ⇒ Object
Bunny’s socket read timeout
90 |
# File 'lib/hutch/config.rb', line 90 number_setting :read_timeout, 11 |
#uri ⇒ Object
RabbitMQ URI (takes precedence over MQ username, password, host, port and vhost settings)
67 |
# File 'lib/hutch/config.rb', line 67 string_setting :uri, nil |
#write_timeout ⇒ Object
Bunny’s socket write timeout
93 |
# File 'lib/hutch/config.rb', line 93 number_setting :write_timeout, 11 |