Skip to content

Commit

Permalink
Merge pull request #739 from stevenpost/fix/provider_retries
Browse files Browse the repository at this point in the history
Remove the retry mechanism from the provider
  • Loading branch information
h-haaks authored Apr 9, 2024
2 parents c99fe8a + fa3365c commit 70dac73
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
17 changes: 4 additions & 13 deletions lib/puppet/provider/mongodb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,30 +127,21 @@ def self.auth_enabled(config = nil)
end

# Mongo Command Wrapper
def self.mongo_eval(cmd, db = 'admin', retries = 10, host = nil)
retry_count = retries
retry_sleep = 3
def self.mongo_eval(cmd, db = 'admin', host = nil)
cmd = mongoshrc_file + cmd if mongoshrc_file

out = nil
begin
out = mongosh_cmd(db, host, cmd)
rescue StandardError => e
retry_count -= 1
if retry_count.positive?
Puppet.debug "Request failed: '#{e.message}' Retry: '#{retries - retry_count}'"
sleep retry_sleep
retry
end
raise Puppet::ExecutionFailure, "Could not evaluate MongoDB shell command: #{cmd}, with: #{e.message}"
end

raise Puppet::ExecutionFailure, "Could not evaluate MongoDB shell command: #{cmd}, with: #{e.message}" unless out

Puppet::Util::MongodbOutput.sanitize(out)
end

def mongo_eval(cmd, db = 'admin', retries = 10, host = nil)
self.class.mongo_eval(cmd, db, retries, host)
def mongo_eval(cmd, db = 'admin', host = nil)
self.class.mongo_eval(cmd, db, host)
end

# Mongo Version checker
Expand Down
8 changes: 4 additions & 4 deletions lib/puppet/provider/mongodb_replset/mongo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,13 @@ def update_settings
raise Puppet::Error, "rs.reconfig() failed to update settings in replicaset #{name}: #{output['errmsg']}" if output['ok'].zero?
end

def mongo_command(command, host, retries = 4)
self.class.mongo_command(command, host, retries)
def mongo_command(command, host)
self.class.mongo_command(command, host)
end

def self.mongo_command(command, host = nil, retries = 4)
def self.mongo_command(command, host = nil)
begin
output = mongo_eval("EJSON.stringify(#{command})", 'admin', retries, host)
output = mongo_eval("EJSON.stringify(#{command})", 'admin', host)
rescue Puppet::ExecutionFailure => e
Puppet.debug "Got an exception: #{e}"
raise
Expand Down

0 comments on commit 70dac73

Please sign in to comment.