lib/consul/async/consul_template.rb in consul-templaterb-1.27.0 vs lib/consul/async/consul_template.rb in consul-templaterb-1.27.1
- old
+ new
@@ -29,11 +29,12 @@
@endp_manager = endpoints_manager
end
def as_json(url, default_value, refresh_delay_secs: 10, **opts)
conf = JSONConfiguration.new(url: url, min_duration: refresh_delay_secs, retry_on_non_diff: refresh_delay_secs, **opts)
- @endp_manager.create_if_missing(url, {}) do
+ endpoint_id = url + opts.to_json
+ @endp_manager.create_if_missing(url, {}, endpoint_id: endpoint_id) do
if default_value.is_a?(Array)
ConsulTemplateJSONArray.new(JSONEndpoint.new(conf, url, default_value))
else
ConsulTemplateJSONObject.new(JSONEndpoint.new(conf, url, default_value))
end
@@ -392,19 +393,24 @@
path = 'v1/auth/token/renew-self'
::Consul::Async::Debug.print_debug 'Setting up vault token renewal'
VaultEndpoint.new(vault_conf, path, :POST, {}, {})
end
- def create_if_missing(path, query_params, fail_fast_errors: @fail_fast_errors, max_consecutive_errors_on_endpoint: @max_consecutive_errors_on_endpoint, agent: nil)
- fqdn = path.dup
- query_params.each_pair do |k, v|
- fqdn = "#{agent}#{fqdn}&#{k}=#{v}"
- end
- tpl = @endpoints[fqdn]
+ def create_if_missing(path, query_params, fail_fast_errors: @fail_fast_errors,
+ max_consecutive_errors_on_endpoint: @max_consecutive_errors_on_endpoint,
+ agent: nil, endpoint_id: nil)
+ endpoint_id ||= begin
+ fqdn = path.dup
+ query_params.each_pair do |k, v|
+ fqdn = "#{agent}#{fqdn}&#{k}=#{v}"
+ end
+ fqdn
+ end
+ tpl = @endpoints[endpoint_id]
unless tpl
tpl = yield
::Consul::Async::Debug.print_debug "path #{path.ljust(64)} #{query_params.inspect}\r"
- @endpoints[fqdn] = tpl
+ @endpoints[endpoint_id] = tpl
tpl.endpoint.on_response do |result|
@net_info[:success] += 1
@net_info[:bytes_read] += result.data.bytesize
@net_info[:changes] += 1 if result.modified?
@net_info[:network_bytes] += result.http.response_header['Content-Length'].to_i