Skip to content

Commit

Permalink
Add an option to raise on failure
Browse files Browse the repository at this point in the history
* When the max attempt of max_failures is reached, we usually do nothing
  and move on
* We might want to fail the run instead of waiting forever or ignore the
  failure

Change-Id: I32719795edb5fbbd081442f54419ff3450e8c5f8
  • Loading branch information
achamo committed Apr 21, 2023
1 parent 26c1d63 commit 828d557
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libraries/primitive_consul_lock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def initialize(options = {})
raise ArgumentError, "You can't set both concurrency and service" if @options[:concurrency] && @options[:service]

@options[:backoff] ||= 5 # seconds
@options[:raise_on_failure] = false

ConsulCommon.setup_consul(@options)

Expand Down Expand Up @@ -86,6 +87,7 @@ def wait_until(action, opts = {})
Chef::Log.info "#{action.to_s.capitalize}ed the lock #{path}"
else
Chef::Log.warn "Will ignore errors and since we've reached #{opts[:max_failures]} errors"
raise "Max attempt #{opts[:max_failures]} reached and asked to raise" if opts[:raise_on_failure]
end
end

Expand Down

0 comments on commit 828d557

Please sign in to comment.