Remove quota usage for obs_meta functions
This commit is contained in:
parent
2621573d71
commit
061956f250
@ -28,7 +28,6 @@ RETURNS TABLE (
|
|||||||
data JSON
|
data JSON
|
||||||
) AS $$
|
) AS $$
|
||||||
from cartodb_services.metrics import metrics
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
|
|
||||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
@ -39,27 +38,19 @@ RETURNS TABLE (
|
|||||||
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
||||||
logger_config = GD["logger_config"]
|
logger_config = GD["logger_config"]
|
||||||
logger = Logger(logger_config)
|
logger = Logger(logger_config)
|
||||||
quota_service = QuotaService(user_obs_config, redis_conn)
|
|
||||||
if not quota_service.check_user_quota():
|
|
||||||
raise Exception('You have reached the limit of your quota')
|
|
||||||
|
|
||||||
with metrics('obs_getdata', user_obs_config, logger):
|
with metrics('obs_getdata', user_obs_config, logger):
|
||||||
try:
|
try:
|
||||||
obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetData($1, $2, $3, $4, $5);", ["text", "text", "geomval[]", "json", "boolean"])
|
obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetData($1, $2, $3, $4, $5);", ["text", "text", "geomval[]", "json", "boolean"])
|
||||||
result = plpy.execute(obs_plan, [username, orgname, geomvals, params, merge])
|
result = plpy.execute(obs_plan, [username, orgname, geomvals, params, merge])
|
||||||
if result:
|
if result:
|
||||||
quota_service.increment_success_service_use()
|
|
||||||
return result
|
return result
|
||||||
else:
|
else:
|
||||||
quota_service.increment_empty_service_use()
|
|
||||||
return None
|
return None
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
import sys
|
import sys
|
||||||
quota_service.increment_failed_service_use()
|
|
||||||
logger.error('Error trying to OBS_GetData', sys.exc_info(), data={"username": username, "orgname": orgname})
|
logger.error('Error trying to OBS_GetData', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
raise Exception('Error trying to OBS_GetData')
|
raise Exception('Error trying to OBS_GetData')
|
||||||
finally:
|
|
||||||
quota_service.increment_total_service_use()
|
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetData(
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetData(
|
||||||
@ -85,7 +76,6 @@ RETURNS TABLE (
|
|||||||
data JSON
|
data JSON
|
||||||
) AS $$
|
) AS $$
|
||||||
from cartodb_services.metrics import metrics
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
|
|
||||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
@ -96,29 +86,21 @@ RETURNS TABLE (
|
|||||||
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
||||||
logger_config = GD["logger_config"]
|
logger_config = GD["logger_config"]
|
||||||
logger = Logger(logger_config)
|
logger = Logger(logger_config)
|
||||||
quota_service = QuotaService(user_obs_config, redis_conn)
|
|
||||||
if not quota_service.check_user_quota():
|
|
||||||
raise Exception('You have reached the limit of your quota')
|
|
||||||
|
|
||||||
with metrics('obs_getdata', user_obs_config, logger):
|
with metrics('obs_getdata', user_obs_config, logger):
|
||||||
try:
|
try:
|
||||||
obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetData($1, $2, $3, $4);", ["text", "text", "text[]", "json"])
|
obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetData($1, $2, $3, $4);", ["text", "text", "text[]", "json"])
|
||||||
result = plpy.execute(obs_plan, [username, orgname, geomrefs, params])
|
result = plpy.execute(obs_plan, [username, orgname, geomrefs, params])
|
||||||
if result:
|
if result:
|
||||||
quota_service.increment_success_service_use()
|
|
||||||
return result
|
return result
|
||||||
else:
|
else:
|
||||||
quota_service.increment_empty_service_use()
|
|
||||||
return None
|
return None
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
import sys
|
import sys
|
||||||
quota_service.increment_failed_service_use()
|
|
||||||
exc_info = sys.exc_info()
|
exc_info = sys.exc_info()
|
||||||
logger.error('%s, %s, %s' % (exc_info[0], exc_info[1], exc_info[2]))
|
logger.error('%s, %s, %s' % (exc_info[0], exc_info[1], exc_info[2]))
|
||||||
logger.error('Error trying to OBS_GetData', exc_info, data={"username": username, "orgname": orgname})
|
logger.error('Error trying to OBS_GetData', exc_info, data={"username": username, "orgname": orgname})
|
||||||
raise Exception('Error trying to OBS_GetData')
|
raise Exception('Error trying to OBS_GetData')
|
||||||
finally:
|
|
||||||
quota_service.increment_total_service_use()
|
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetMeta(
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetMeta(
|
||||||
@ -144,7 +126,6 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetMeta(
|
|||||||
target_geoms INTEGER DEFAULT NULL)
|
target_geoms INTEGER DEFAULT NULL)
|
||||||
RETURNS JSON AS $$
|
RETURNS JSON AS $$
|
||||||
from cartodb_services.metrics import metrics
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
|
|
||||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
@ -155,25 +136,17 @@ RETURNS JSON AS $$
|
|||||||
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
||||||
logger_config = GD["logger_config"]
|
logger_config = GD["logger_config"]
|
||||||
logger = Logger(logger_config)
|
logger = Logger(logger_config)
|
||||||
quota_service = QuotaService(user_obs_config, redis_conn)
|
|
||||||
if not quota_service.check_user_quota():
|
|
||||||
raise Exception('You have reached the limit of your quota')
|
|
||||||
|
|
||||||
with metrics('obs_getmeta', user_obs_config, logger):
|
with metrics('obs_getmeta', user_obs_config, logger):
|
||||||
try:
|
try:
|
||||||
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetMeta($1, $2, $3, $4, $5, $6, $7) as meta;", ["text", "text", "Geometry (Geometry, 4326)", "json", "integer", "integer", "integer"])
|
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetMeta($1, $2, $3, $4, $5, $6, $7) as meta;", ["text", "text", "Geometry (Geometry, 4326)", "json", "integer", "integer", "integer"])
|
||||||
result = plpy.execute(obs_plan, [username, orgname, geom, params, max_timespan_rank, max_score_rank, target_geoms])
|
result = plpy.execute(obs_plan, [username, orgname, geom, params, max_timespan_rank, max_score_rank, target_geoms])
|
||||||
if result:
|
if result:
|
||||||
quota_service.increment_success_service_use()
|
|
||||||
return result[0]['meta']
|
return result[0]['meta']
|
||||||
else:
|
else:
|
||||||
quota_service.increment_empty_service_use()
|
|
||||||
return None
|
return None
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
import sys
|
import sys
|
||||||
quota_service.increment_failed_service_use()
|
|
||||||
logger.error('Error trying to OBS_GetMeta', sys.exc_info(), data={"username": username, "orgname": orgname})
|
logger.error('Error trying to OBS_GetMeta', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
raise Exception('Error trying to OBS_GetMeta')
|
raise Exception('Error trying to OBS_GetMeta')
|
||||||
finally:
|
|
||||||
quota_service.increment_total_service_use()
|
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
@ -730,7 +730,6 @@ RETURNS TABLE (
|
|||||||
data JSON
|
data JSON
|
||||||
) AS $$
|
) AS $$
|
||||||
from cartodb_services.metrics import metrics
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
|
|
||||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
@ -741,27 +740,19 @@ RETURNS TABLE (
|
|||||||
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
||||||
logger_config = GD["logger_config"]
|
logger_config = GD["logger_config"]
|
||||||
logger = Logger(logger_config)
|
logger = Logger(logger_config)
|
||||||
quota_service = QuotaService(user_obs_config, redis_conn)
|
|
||||||
if not quota_service.check_user_quota():
|
|
||||||
raise Exception('You have reached the limit of your quota')
|
|
||||||
|
|
||||||
with metrics('obs_getdata', user_obs_config, logger):
|
with metrics('obs_getdata', user_obs_config, logger):
|
||||||
try:
|
try:
|
||||||
obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetData($1, $2, $3, $4, $5);", ["text", "text", "geomval[]", "json", "boolean"])
|
obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetData($1, $2, $3, $4, $5);", ["text", "text", "geomval[]", "json", "boolean"])
|
||||||
result = plpy.execute(obs_plan, [username, orgname, geomvals, params, merge])
|
result = plpy.execute(obs_plan, [username, orgname, geomvals, params, merge])
|
||||||
if result:
|
if result:
|
||||||
quota_service.increment_success_service_use()
|
|
||||||
return result
|
return result
|
||||||
else:
|
else:
|
||||||
quota_service.increment_empty_service_use()
|
|
||||||
return None
|
return None
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
import sys
|
import sys
|
||||||
quota_service.increment_failed_service_use()
|
|
||||||
logger.error('Error trying to OBS_GetData', sys.exc_info(), data={"username": username, "orgname": orgname})
|
logger.error('Error trying to OBS_GetData', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
raise Exception('Error trying to OBS_GetData')
|
raise Exception('Error trying to OBS_GetData')
|
||||||
finally:
|
|
||||||
quota_service.increment_total_service_use()
|
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetData(
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetData(
|
||||||
@ -787,7 +778,6 @@ RETURNS TABLE (
|
|||||||
data JSON
|
data JSON
|
||||||
) AS $$
|
) AS $$
|
||||||
from cartodb_services.metrics import metrics
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
|
|
||||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
@ -798,29 +788,21 @@ RETURNS TABLE (
|
|||||||
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
||||||
logger_config = GD["logger_config"]
|
logger_config = GD["logger_config"]
|
||||||
logger = Logger(logger_config)
|
logger = Logger(logger_config)
|
||||||
quota_service = QuotaService(user_obs_config, redis_conn)
|
|
||||||
if not quota_service.check_user_quota():
|
|
||||||
raise Exception('You have reached the limit of your quota')
|
|
||||||
|
|
||||||
with metrics('obs_getdata', user_obs_config, logger):
|
with metrics('obs_getdata', user_obs_config, logger):
|
||||||
try:
|
try:
|
||||||
obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetData($1, $2, $3, $4);", ["text", "text", "text[]", "json"])
|
obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetData($1, $2, $3, $4);", ["text", "text", "text[]", "json"])
|
||||||
result = plpy.execute(obs_plan, [username, orgname, geomrefs, params])
|
result = plpy.execute(obs_plan, [username, orgname, geomrefs, params])
|
||||||
if result:
|
if result:
|
||||||
quota_service.increment_success_service_use()
|
|
||||||
return result
|
return result
|
||||||
else:
|
else:
|
||||||
quota_service.increment_empty_service_use()
|
|
||||||
return None
|
return None
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
import sys
|
import sys
|
||||||
quota_service.increment_failed_service_use()
|
|
||||||
exc_info = sys.exc_info()
|
exc_info = sys.exc_info()
|
||||||
logger.error('%s, %s, %s' % (exc_info[0], exc_info[1], exc_info[2]))
|
logger.error('%s, %s, %s' % (exc_info[0], exc_info[1], exc_info[2]))
|
||||||
logger.error('Error trying to OBS_GetData', exc_info, data={"username": username, "orgname": orgname})
|
logger.error('Error trying to OBS_GetData', exc_info, data={"username": username, "orgname": orgname})
|
||||||
raise Exception('Error trying to OBS_GetData')
|
raise Exception('Error trying to OBS_GetData')
|
||||||
finally:
|
|
||||||
quota_service.increment_total_service_use()
|
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetMeta(
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetMeta(
|
||||||
@ -846,7 +828,6 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetMeta(
|
|||||||
target_geoms INTEGER DEFAULT NULL)
|
target_geoms INTEGER DEFAULT NULL)
|
||||||
RETURNS JSON AS $$
|
RETURNS JSON AS $$
|
||||||
from cartodb_services.metrics import metrics
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
|
|
||||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
@ -857,27 +838,19 @@ RETURNS JSON AS $$
|
|||||||
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
||||||
logger_config = GD["logger_config"]
|
logger_config = GD["logger_config"]
|
||||||
logger = Logger(logger_config)
|
logger = Logger(logger_config)
|
||||||
quota_service = QuotaService(user_obs_config, redis_conn)
|
|
||||||
if not quota_service.check_user_quota():
|
|
||||||
raise Exception('You have reached the limit of your quota')
|
|
||||||
|
|
||||||
with metrics('obs_getmeta', user_obs_config, logger):
|
with metrics('obs_getmeta', user_obs_config, logger):
|
||||||
try:
|
try:
|
||||||
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetMeta($1, $2, $3, $4, $5, $6, $7) as meta;", ["text", "text", "Geometry (Geometry, 4326)", "json", "integer", "integer", "integer"])
|
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetMeta($1, $2, $3, $4, $5, $6, $7) as meta;", ["text", "text", "Geometry (Geometry, 4326)", "json", "integer", "integer", "integer"])
|
||||||
result = plpy.execute(obs_plan, [username, orgname, geom, params, max_timespan_rank, max_score_rank, target_geoms])
|
result = plpy.execute(obs_plan, [username, orgname, geom, params, max_timespan_rank, max_score_rank, target_geoms])
|
||||||
if result:
|
if result:
|
||||||
quota_service.increment_success_service_use()
|
|
||||||
return result[0]['meta']
|
return result[0]['meta']
|
||||||
else:
|
else:
|
||||||
quota_service.increment_empty_service_use()
|
|
||||||
return None
|
return None
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
import sys
|
import sys
|
||||||
quota_service.increment_failed_service_use()
|
|
||||||
logger.error('Error trying to OBS_GetMeta', sys.exc_info(), data={"username": username, "orgname": orgname})
|
logger.error('Error trying to OBS_GetMeta', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
raise Exception('Error trying to OBS_GetMeta')
|
raise Exception('Error trying to OBS_GetMeta')
|
||||||
finally:
|
|
||||||
quota_service.increment_total_service_use()
|
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_Search(
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_Search(
|
||||||
username TEXT,
|
username TEXT,
|
||||||
|
@ -593,7 +593,6 @@ RETURNS TABLE (
|
|||||||
data JSON
|
data JSON
|
||||||
) AS $$
|
) AS $$
|
||||||
from cartodb_services.metrics import metrics
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
|
|
||||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
@ -604,27 +603,19 @@ RETURNS TABLE (
|
|||||||
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
||||||
logger_config = GD["logger_config"]
|
logger_config = GD["logger_config"]
|
||||||
logger = Logger(logger_config)
|
logger = Logger(logger_config)
|
||||||
quota_service = QuotaService(user_obs_config, redis_conn)
|
|
||||||
if not quota_service.check_user_quota():
|
|
||||||
raise Exception('You have reached the limit of your quota')
|
|
||||||
|
|
||||||
with metrics('obs_getdata', user_obs_config, logger):
|
with metrics('obs_getdata', user_obs_config, logger):
|
||||||
try:
|
try:
|
||||||
obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetData($1, $2, $3, $4, $5);", ["text", "text", "geomval[]", "json", "boolean"])
|
obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetData($1, $2, $3, $4, $5);", ["text", "text", "geomval[]", "json", "boolean"])
|
||||||
result = plpy.execute(obs_plan, [username, orgname, geomvals, params, merge])
|
result = plpy.execute(obs_plan, [username, orgname, geomvals, params, merge])
|
||||||
if result:
|
if result:
|
||||||
quota_service.increment_success_service_use()
|
|
||||||
return result
|
return result
|
||||||
else:
|
else:
|
||||||
quota_service.increment_empty_service_use()
|
|
||||||
return None
|
return None
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
import sys
|
import sys
|
||||||
quota_service.increment_failed_service_use()
|
|
||||||
logger.error('Error trying to OBS_GetData', sys.exc_info(), data={"username": username, "orgname": orgname})
|
logger.error('Error trying to OBS_GetData', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
raise Exception('Error trying to OBS_GetData')
|
raise Exception('Error trying to OBS_GetData')
|
||||||
finally:
|
|
||||||
quota_service.increment_total_service_use()
|
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetData(
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetData(
|
||||||
@ -650,7 +641,6 @@ RETURNS TABLE (
|
|||||||
data JSON
|
data JSON
|
||||||
) AS $$
|
) AS $$
|
||||||
from cartodb_services.metrics import metrics
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
|
|
||||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
@ -661,29 +651,21 @@ RETURNS TABLE (
|
|||||||
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
||||||
logger_config = GD["logger_config"]
|
logger_config = GD["logger_config"]
|
||||||
logger = Logger(logger_config)
|
logger = Logger(logger_config)
|
||||||
quota_service = QuotaService(user_obs_config, redis_conn)
|
|
||||||
if not quota_service.check_user_quota():
|
|
||||||
raise Exception('You have reached the limit of your quota')
|
|
||||||
|
|
||||||
with metrics('obs_getdata', user_obs_config, logger):
|
with metrics('obs_getdata', user_obs_config, logger):
|
||||||
try:
|
try:
|
||||||
obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetData($1, $2, $3, $4);", ["text", "text", "text[]", "json"])
|
obs_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._OBS_GetData($1, $2, $3, $4);", ["text", "text", "text[]", "json"])
|
||||||
result = plpy.execute(obs_plan, [username, orgname, geomrefs, params])
|
result = plpy.execute(obs_plan, [username, orgname, geomrefs, params])
|
||||||
if result:
|
if result:
|
||||||
quota_service.increment_success_service_use()
|
|
||||||
return result
|
return result
|
||||||
else:
|
else:
|
||||||
quota_service.increment_empty_service_use()
|
|
||||||
return None
|
return None
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
import sys
|
import sys
|
||||||
quota_service.increment_failed_service_use()
|
|
||||||
exc_info = sys.exc_info()
|
exc_info = sys.exc_info()
|
||||||
logger.error('%s, %s, %s' % (exc_info[0], exc_info[1], exc_info[2]))
|
logger.error('%s, %s, %s' % (exc_info[0], exc_info[1], exc_info[2]))
|
||||||
logger.error('Error trying to OBS_GetData', exc_info, data={"username": username, "orgname": orgname})
|
logger.error('Error trying to OBS_GetData', exc_info, data={"username": username, "orgname": orgname})
|
||||||
raise Exception('Error trying to OBS_GetData')
|
raise Exception('Error trying to OBS_GetData')
|
||||||
finally:
|
|
||||||
quota_service.increment_total_service_use()
|
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetMeta(
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._OBS_GetMeta(
|
||||||
@ -709,7 +691,6 @@ CREATE OR REPLACE FUNCTION cdb_dataservices_server.OBS_GetMeta(
|
|||||||
target_geoms INTEGER DEFAULT NULL)
|
target_geoms INTEGER DEFAULT NULL)
|
||||||
RETURNS JSON AS $$
|
RETURNS JSON AS $$
|
||||||
from cartodb_services.metrics import metrics
|
from cartodb_services.metrics import metrics
|
||||||
from cartodb_services.metrics import QuotaService
|
|
||||||
from cartodb_services.tools import Logger,LoggerConfig
|
from cartodb_services.tools import Logger,LoggerConfig
|
||||||
|
|
||||||
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username))
|
||||||
@ -720,25 +701,17 @@ RETURNS JSON AS $$
|
|||||||
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
||||||
logger_config = GD["logger_config"]
|
logger_config = GD["logger_config"]
|
||||||
logger = Logger(logger_config)
|
logger = Logger(logger_config)
|
||||||
quota_service = QuotaService(user_obs_config, redis_conn)
|
|
||||||
if not quota_service.check_user_quota():
|
|
||||||
raise Exception('You have reached the limit of your quota')
|
|
||||||
|
|
||||||
with metrics('obs_getmeta', user_obs_config, logger):
|
with metrics('obs_getmeta', user_obs_config, logger):
|
||||||
try:
|
try:
|
||||||
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetMeta($1, $2, $3, $4, $5, $6, $7) as meta;", ["text", "text", "Geometry (Geometry, 4326)", "json", "integer", "integer", "integer"])
|
obs_plan = plpy.prepare("SELECT cdb_dataservices_server._OBS_GetMeta($1, $2, $3, $4, $5, $6, $7) as meta;", ["text", "text", "Geometry (Geometry, 4326)", "json", "integer", "integer", "integer"])
|
||||||
result = plpy.execute(obs_plan, [username, orgname, geom, params, max_timespan_rank, max_score_rank, target_geoms])
|
result = plpy.execute(obs_plan, [username, orgname, geom, params, max_timespan_rank, max_score_rank, target_geoms])
|
||||||
if result:
|
if result:
|
||||||
quota_service.increment_success_service_use()
|
|
||||||
return result[0]['meta']
|
return result[0]['meta']
|
||||||
else:
|
else:
|
||||||
quota_service.increment_empty_service_use()
|
|
||||||
return None
|
return None
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
import sys
|
import sys
|
||||||
quota_service.increment_failed_service_use()
|
|
||||||
logger.error('Error trying to OBS_GetMeta', sys.exc_info(), data={"username": username, "orgname": orgname})
|
logger.error('Error trying to OBS_GetMeta', sys.exc_info(), data={"username": username, "orgname": orgname})
|
||||||
raise Exception('Error trying to OBS_GetMeta')
|
raise Exception('Error trying to OBS_GetMeta')
|
||||||
finally:
|
|
||||||
quota_service.increment_total_service_use()
|
|
||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
Loading…
Reference in New Issue
Block a user