Skip to content

Commit

Permalink
Make retry helper method more general
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleknap committed Jun 6, 2017
1 parent 7708e09 commit 2b2997c
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions chalice/awsclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,16 @@ def create_function(self,
kwargs['Timeout'] = timeout
if memory_size is not None:
kwargs['MemorySize'] = memory_size
return self._create_or_update_function_with_retries(
'create_function', kwargs)['FunctionArn']
return self._call_client_method_with_retries(
self._client('lambda').create_function, kwargs)['FunctionArn']

def _create_or_update_function_with_retries(self, method_name, kwargs):
# type: (str, Dict[str, Any]) -> Dict[str, Any]
def _call_client_method_with_retries(self, method, kwargs):
# type: (Callable[..., Any], Dict[str, Any]) -> Dict[str, Any]
client = self._client('lambda')
attempts = 0
while True:
try:
response = getattr(client, method_name)(**kwargs)
response = method(**kwargs)
except client.exceptions.InvalidParameterValueException:
# We're assuming that if we receive an
# InvalidParameterValueException, it's because
Expand Down Expand Up @@ -154,8 +154,8 @@ def update_function(self,
kwargs['Role'] = role_arn
if kwargs:
kwargs['FunctionName'] = function_name
self._create_or_update_function_with_retries(
'update_function_configuration', kwargs)
self._call_client_method_with_retries(
self._client('lambda').update_function_configuration, kwargs)
if tags is not None:
self._update_function_tags(return_value['FunctionArn'], tags)
return return_value
Expand Down

0 comments on commit 2b2997c

Please sign in to comment.