#NEWLINE# def wrap_aws_rate_limited_call( self , awsfunc , * args , **nargs ) : #NEWLINE# #INDENT# attempts = 0 #NEWLINE# def increase_delay( ) : #NEWLINE# #INDENT# if ( self . rate_limit_delay == 0 ) : #NEWLINE# #INDENT# self . rate_limit_delay = 1 #NEWLINE# app . logger . warn ( ( 'Being rate-limited by AWS. Increasing delay on tech {} ' + 'in account {} from 0 to 1 second. Attempt {}' ) . format ( self . index , self . accounts , attempts ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( self . rate_limit_delay < 4 ) : #NEWLINE# #INDENT# self . rate_limit_delay = ( self . rate_limit_delay * 2 ) #NEWLINE# app . logger . warn ( ( 'Still being rate-limited by AWS. Increasing delay on tech {} ' + 'in account {} to {} seconds. Attempt {}' ) . format ( self . index , self . accounts , self . rate_limit_delay , attempts ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# app . logger . warn ( ( 'Still being rate-limited by AWS. Keeping delay on tech {} ' + 'in account {} at {} seconds. Attempt {}' ) . format ( self . index , self . accounts , self . rate_limit_delay , attempts ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# while True : #NEWLINE# #INDENT# attempts = ( attempts + 1 ) #NEWLINE# try : #NEWLINE# #INDENT# if ( self . rate_limit_delay > 0 ) : #NEWLINE# #INDENT# time . sleep ( self . rate_limit_delay ) #NEWLINE# #UNINDENT# retval = awsfunc ( * args , ** nargs ) #NEWLINE# if ( retval . rate_limit_delay > 0 ) : #NEWLINE# #INDENT# app . logger . warn ( 'Successfully Executed Rate-Limited Function. Tech: {} Account: {}. Removing sleep period.' . format ( self . index , self . accounts ) ) #NEWLINE# self . rate_limit_delay = 0 #NEWLINE# #UNINDENT# return retval #NEWLINE# #UNINDENT# except BotoServerError as e : #NEWLINE# #INDENT# if ( not ( e . error_code == 'Throttling' ) ) : #NEWLINE# #INDENT# raise e #NEWLINE# #UNINDENT# increase_delay ( ) #NEWLINE# #UNINDENT# except ClientError as e : #NEWLINE# #INDENT# if ( not ( e . response [ 'Error' ] [ 'Code' ] == 'Throttling' ) ) : #NEWLINE# #INDENT# raise e #NEWLINE# #UNINDENT# increase_delay ( )