In case of general error, failed service use should be incremented by searches length

This commit is contained in:
Juan Ignacio Sánchez Lara 2018-07-19 21:19:00 +02:00
parent fd097724f1
commit cd5e6510a6
2 changed files with 9 additions and 2 deletions

View File

@ -54,11 +54,13 @@ def run_street_point_geocoder(plpy, GD, geocoder, service_manager, username, org
service_manager.quota_service.increment_empty_service_use(len(searches))
return []
except QuotaExceededException as qe:
logger.debug('QuotaExceededException at run_street_point_geocoder', qe,
data={"username": username, "orgname": orgname})
service_manager.quota_service.increment_failed_service_use(len(searches))
return []
except BaseException as e:
import sys
service_manager.quota_service.increment_failed_service_use()
service_manager.quota_service.increment_failed_service_use(len(searches))
service_manager.logger.error('Error trying to bulk geocode street point', sys.exc_info(), data={"username": username, "orgname": orgname})
raise Exception('Error trying to bulk geocode street')
finally:

View File

@ -8,11 +8,13 @@ from cartodb_services.geocoder import run_street_point_geocoder
class TestRunStreetPointGeocoder(TestCase):
def test_count_increment_total_service_use_on_error(self):
def test_count_increment_total_and_failed_service_use_on_error(self):
quota_service_mock = Mock()
service_manager_mock = Mock()
service_manager_mock.quota_service = quota_service_mock
service_manager_mock.assert_within_limits = \
Mock(side_effect=Exception('Fail!'))
searches = []
@ -27,3 +29,6 @@ class TestRunStreetPointGeocoder(TestCase):
quota_service_mock.increment_total_service_use. \
assert_called_once_with(len(searches))
quota_service_mock.increment_failed_service_use. \
assert_called_once_with(len(searches))