Skip to content

Commit

Permalink
Fix the instrumentation path for failed retriable exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
gmr committed Sep 26, 2016
1 parent 8a7894a commit e51b778
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ before_install:
- printf "[default]\nregion=us-east-1\noutput=json\n" > /home/travis/.aws/config
- printf "[default]\naws_access_key_id = FAKE0000000000000000\naws_secret_access_key = FAKE000000000000000000000000000000000000\n" > /home/travis/.aws/credentials
env:
ASYNC_TEST_TIMEOUT: 15
DYNAMODB_ENDPOINT: http://localhost:7777
install:
- pip install -r requires/testing.txt
Expand Down
6 changes: 5 additions & 1 deletion sprockets_dynamodb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,9 @@ def execute(self, action, parameters):
exceptions.ThrottlingException,
exceptions.ThroughputExceeded) as error:
if attempt == self._max_retries:
raise error
if self._instrumentation_callback:
self._instrumentation_callback(measurements)
self._on_exception(error)
duration = self._sleep_duration(attempt)
self.logger.warning('%r on attempt %i, sleeping %.2f seconds',
error, attempt, duration)
Expand All @@ -1295,6 +1297,7 @@ def set_error_callback(self, callback):
:param method callback: The method to invoke
"""
LOGGER.debug('Setting error callback: %r', callback)
self._on_error = callback

def set_instrumentation_callback(self, callback):
Expand All @@ -1304,6 +1307,7 @@ def set_instrumentation_callback(self, callback):
:param method callback: The method to invoke
"""
LOGGER.debug('Setting instrumentation callback: %r', callback)
self._instrumentation_callback = callback

def _execute(self, action, parameters, attempt, measurements):
Expand Down
2 changes: 1 addition & 1 deletion tests/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def instrumentation_check(measurements):
self.assertEqual(measurement.attempt, attempt + 1)
self.assertEqual(measurement.action, 'CreateTable')
self.assertEqual(measurement.table, definition['TableName'])
self.assertEqual(measurement.error, None)
self.assertEqual(measurement.error, 'RequestException')
self.assertEqual(len(measurements), 3)
wait_for_measurements.set()

Expand Down

0 comments on commit e51b778

Please sign in to comment.