Skip to content

Commit f54680f

Browse files
Merge pull request #79 from mougams/fix_consul_lock
Fix consul lib semaphore
2 parents 4152134 + 11e6b34 commit f54680f

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

libraries/consul.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ def self.setup_consul(options)
1919
end
2020
end
2121

22-
def self.update_backup_url(options)
22+
def self.update_backup_url(consul_backup_url: nil)
2323
require 'diplomat'
24-
return unless options[:consul_backup_url]
24+
return if consul_backup_url.nil?
2525

2626
Diplomat.configure do |config|
27-
config.url = options[:consul_backup_url]
27+
config.url = consul_backup_url
2828
end
2929
end
3030

libraries/primitive_consul_lock.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def semaphore_class
5151

5252
def semaphore
5353
# this object cannot be reused after enter/exit
54-
semaphore_class.get_or_create(path, concurrency: concurrency, dc: @options[:datacenter], token: @options[:token])
54+
semaphore_class.get_or_create(path, concurrency: concurrency, dc: @options[:datacenter], token: @options[:token], consul_backup_url: @options[:consul_backup_url])
5555
end
5656

5757
def backoff(start_time, current_try)
@@ -129,7 +129,7 @@ def self.get_or_create(path, concurrency:, **kwargs)
129129
Chef::Log.info "Consul did not respond, wait #{retry_secs} seconds and retry to let it (re)start: #{e}"
130130
sleep retry_secs
131131
connection_failed_count += 1
132-
ConsulCommon.update_backup_url(@options) if connection_failed_count == retry_total_attempts / 2
132+
ConsulCommon.update_backup_url(kwargs[:consul_backup_url]) if connection_failed_count == retry_total_attempts / 2
133133
(retry_left -= 1).positive? ? retry : raise
134134
rescue Diplomat::KeyNotFound
135135
Chef::Log.info "Lock for #{path} did not exist, creating with value #{value}"

spec/unit/primitive_consul_lock_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
lock = double('lock')
6363
expect(lock).to receive(:enter).with(name: 'my_node').and_return(true)
6464

65-
expect(Semaphore).to receive(:get_or_create).with('chef_lock/test', concurrency: 3, dc: nil, token: nil).and_return(lock)
65+
expect(Semaphore).to receive(:get_or_create).with('chef_lock/test', concurrency: 3, dc: nil, token: nil, consul_backup_url: nil).and_return(lock)
6666

6767
choregraphie_service.before.each(&:call)
6868
end

0 commit comments

Comments
 (0)