#NEWLINE# def __wrap_method_with_call_and_maybe_retry( self , f ) : #NEWLINE# #INDENT# 'Wrap method f in a retry loop.' #NEWLINE# def call_and_maybe_retry( * args , **kwargs ) : #NEWLINE# #INDENT# backoff = self . __backoff #NEWLINE# tries = 0 #NEWLINE# while ( ( not self . __max_tries ) or ( tries < self . __max_tries ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# return f ( * args , ** kwargs ) #NEWLINE# #UNINDENT# except Exception as ex : #NEWLINE# #INDENT# if ( self . __retry_if ( ex ) and ( ( tries < ( self . __max_tries - 1 ) ) or ( not self . __max_tries ) ) ) : #NEWLINE# #INDENT# log . info ( ( 'Got retriable error: %r' % ex ) ) #NEWLINE# log . info ( ( 'Backing off for %.1f seconds' % backoff ) ) #NEWLINE# time . sleep ( backoff ) #NEWLINE# tries += 1 #NEWLINE# backoff *= self . __multiplier #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# ( call_and_maybe_retry . __name__ == f . __name__ ) #NEWLINE# return call_and_maybe_retry