Module: Mongo

Defined in:
lib/disbatch.rb

Class Method Summary collapse

Class Method Details

.try(max_retries = 4, interval = 0.5) ⇒ Object

Wrap a MongoDB operation for retry

Parameters:

  • max_retries (Integer) (defaults to: 4)

    maximum number of times to attempt to connect

  • interval (Float) (defaults to: 0.5)

    frequency of retry attempts



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/disbatch.rb', line 61

def self.try(max_retries=4,interval=0.5)
	retries = 0
	begin
		yield
	rescue Mongo::ConnectionFailure => ex
		retries +=1
		raise ex if retries > max_retries
		sleep(interval)
		retry
	end
end