From 80963e25898542eb05eec286f7cfd9b79b0fc96c Mon Sep 17 00:00:00 2001 From: Mario de Frutos Date: Wed, 26 Oct 2016 16:17:41 +0200 Subject: [PATCH] 504 errors return empty data instead of raise exception Due to some problems in Mapzen, we're receiving 504 errors from their servers. To mitigate this problem, instead of raise an exception, we're going to return empty data for that point --- .../cartodb_services/cartodb_services/mapzen/isolines.py | 2 +- .../cartodb_services/mapzen/matrix_client.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/server/lib/python/cartodb_services/cartodb_services/mapzen/isolines.py b/server/lib/python/cartodb_services/cartodb_services/mapzen/isolines.py index c9e16fa..e6f51be 100644 --- a/server/lib/python/cartodb_services/cartodb_services/mapzen/isolines.py +++ b/server/lib/python/cartodb_services/cartodb_services/mapzen/isolines.py @@ -86,7 +86,7 @@ class MapzenIsolines: def calculate_isoline(self, origin, costing_model, isorange, upper_rmax, cost_variable, unit_factor=1.0): # NOTE: not for production - self._logger.debug('Calculate isoline', data={"origin": origin, "costing_model": costing_model, "isorange": isorange}) + # self._logger.debug('Calculate isoline', data={"origin": origin, "costing_model": costing_model, "isorange": isorange}) # Formally, a solution is an array of {angle, radius, lat, lon, cost} with cardinality NUMBER_OF_ANGLES # we're looking for a solution in which abs(cost - isorange) / isorange <= TOLERANCE diff --git a/server/lib/python/cartodb_services/cartodb_services/mapzen/matrix_client.py b/server/lib/python/cartodb_services/cartodb_services/mapzen/matrix_client.py index 96d11d0..e6bf3e3 100644 --- a/server/lib/python/cartodb_services/cartodb_services/mapzen/matrix_client.py +++ b/server/lib/python/cartodb_services/cartodb_services/mapzen/matrix_client.py @@ -57,6 +57,12 @@ class MatrixClient: # isolines generation if response.status_code == requests.codes.bad_request: return {} + elif response.status_coe == 504: + # Due to some unsolved problems in the Mapzen Matrix API we're + # getting randomly 504, probably timeouts. To avoid raise an + # exception in all the jobs, for now we're going to return + # empty in that case + return {} else: raise ServiceException("Error trying to get matrix distance from mapzen", response)