Small PoC with rratelimit #346
This commit is contained in:
@@ -169,6 +169,16 @@ RETURNS Geometry AS $$
|
|||||||
|
|
||||||
redis_metrics_connection = RedisMetricsConnectionFactory(environment, server_config_backend).get()
|
redis_metrics_connection = RedisMetricsConnectionFactory(environment, server_config_backend).get()
|
||||||
|
|
||||||
|
#-- e.g: RateLimit(service='geocoder', user=username, max_requests=2, period=60)
|
||||||
|
#-- rate_limiter = RateLimitBuilder(service='geocoder', user=username)
|
||||||
|
#-- How to pass the redis config along?
|
||||||
|
#-- rate_limiter_geocoder_config = RateLimiterUserConfigFactory(redis_metrics_connection, service='geocoder', user=username)
|
||||||
|
from rratelimit import Limiter
|
||||||
|
rate_limiter = Limiter(redis_metrics_connection, action='geocode', limit=2, period=60)
|
||||||
|
if not rate_limiter.checked_insert(username):
|
||||||
|
raise Exception('Rate limit exceeded')
|
||||||
|
|
||||||
|
|
||||||
quota_service = QuotaService(mapzen_geocoder_config, redis_metrics_connection)
|
quota_service = QuotaService(mapzen_geocoder_config, redis_metrics_connection)
|
||||||
if not quota_service.check_user_quota():
|
if not quota_service.check_user_quota():
|
||||||
raise Exception('You have reached the limit of your quota')
|
raise Exception('You have reached the limit of your quota')
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ python-dateutil==2.2
|
|||||||
googlemaps==2.4.2
|
googlemaps==2.4.2
|
||||||
rollbar==0.13.2
|
rollbar==0.13.2
|
||||||
# Dependency for googlemaps package
|
# Dependency for googlemaps package
|
||||||
requests<=2.9.1
|
requests==2.9.1
|
||||||
|
rratelimit==0.0.4
|
||||||
|
|
||||||
# Test
|
# Test
|
||||||
mock==1.3.0
|
mock==1.3.0
|
||||||
|
|||||||
Reference in New Issue
Block a user