diff --git a/server/lib/python/cartodb_services/cartodb_services/metrics/config.py b/server/lib/python/cartodb_services/cartodb_services/metrics/config.py index d6e7271..dc5a930 100644 --- a/server/lib/python/cartodb_services/cartodb_services/metrics/config.py +++ b/server/lib/python/cartodb_services/cartodb_services/metrics/config.py @@ -116,6 +116,7 @@ class RoutingConfig(ServiceConfig): ROUTING_PROVIDER_KEY = 'routing_provider' MAPZEN_PROVIDER = 'mapzen' DEFAULT_PROVIDER = 'mapzen' + QUOTA_KEY = 'mapzen_routing_quota' def __init__(self, redis_connection, db_conn, username, orgname=None): super(RoutingConfig, self).__init__(redis_connection, db_conn, @@ -124,7 +125,7 @@ class RoutingConfig(ServiceConfig): if not self._routing_provider: self._routing_provider = self.DEFAULT_PROVIDER self._mapzen_api_key = self._db_config.mapzen_routing_api_key - self._monthly_quota = self._db_config.mapzen_routing_monthly_quota + self._set_monthly_quota() self._period_end_date = date_parse(self._redis_config[self.PERIOD_END_DATE]) @property @@ -144,6 +145,19 @@ class RoutingConfig(ServiceConfig): def period_end_date(self): return self._period_end_date + def _set_monthly_quota(self): + self._monthly_quota = self._get_effective_monthly_quota() + + def _get_effective_monthly_quota(self): + quota_from_redis = self._redis_config[self.QUOTA_KEY] + if quota_from_redis and quota_from_redis <> '': + return int(quota_from_redis) + else: + return self._db_config.mapzen_routing_monthly_quota + + + + class IsolinesRoutingConfig(ServiceConfig): @@ -547,6 +561,7 @@ class ServicesRedisConfig: GOOGLE_GEOCODER_CLIENT_ID = 'google_maps_client_id' QUOTA_KEY = 'geocoding_quota' ISOLINES_QUOTA_KEY = 'here_isolines_quota' + ROUTING_QUOTA_KEY = 'mapzen_routing_quota' OBS_SNAPSHOT_QUOTA_KEY = 'obs_snapshot_quota' OBS_GENERAL_QUOTA_KEY = 'obs_general_quota' PERIOD_END_DATE = 'period_end_date' @@ -574,6 +589,9 @@ class ServicesRedisConfig: if self.ROUTING_PROVIDER_KEY not in user_config: user_config[self.ROUTING_PROVIDER_KEY] = '' + # Mapzen routing quota might be not present + user_config[self.ROUTING_QUOTA_KEY] = user_config.get(self.ROUTING_QUOTA_KEY) + if orgname: self.__get_organization_config(orgname, user_config) @@ -587,6 +605,7 @@ class ServicesRedisConfig: else: user_config[self.QUOTA_KEY] = org_config[self.QUOTA_KEY] user_config[self.ISOLINES_QUOTA_KEY] = org_config[self.ISOLINES_QUOTA_KEY] + user_config[self.ROUTING_QUOTA_KEY] = org_config.get(self.ROUTING_QUOTA_KEY) if self.OBS_SNAPSHOT_QUOTA_KEY in org_config: user_config[self.OBS_SNAPSHOT_QUOTA_KEY] = org_config[self.OBS_SNAPSHOT_QUOTA_KEY] if self.OBS_GENERAL_QUOTA_KEY in org_config: