Added soft/hard geocoder limit
This commit is contained in:
@@ -15,7 +15,8 @@ class QuotaService:
|
||||
user_quota = self.user_service.user_quota()
|
||||
today = date.today()
|
||||
current_used = self.user_service.used_quota_month(today.year, today.month)
|
||||
return True if (current_used + 1) < user_quota else False
|
||||
soft_geocoder_limit = self.user_service.soft_geocoder_limit()
|
||||
return True if soft_geocoder_limit or (current_used + 1) < user_quota else False
|
||||
|
||||
def increment_geocoder_use(self, amount=1):
|
||||
today = date.today()
|
||||
|
||||
@@ -5,6 +5,8 @@ class UserService:
|
||||
""" Class to manage all the user info """
|
||||
|
||||
GEOCODING_QUOTA_KEY = "geocoding_quota"
|
||||
GEOCODING_SOFT_LIMIT_KEY = "soft_geocoder_limit"
|
||||
|
||||
REDIS_CONNECTION_KEY = "redis_connection"
|
||||
REDIS_CONNECTION_HOST = "redis_host"
|
||||
REDIS_CONNECTION_PORT = "redis_port"
|
||||
@@ -29,6 +31,11 @@ class UserService:
|
||||
user_quota = self._redis_connection.hget(self.__get_user_redis_key(), self.GEOCODING_QUOTA_KEY)
|
||||
return int(user_quota) if user_quota and int(user_quota) >= 0 else 0
|
||||
|
||||
def soft_geocoder_limit(self):
|
||||
""" Check what kind of limit the user has """
|
||||
soft_limit = self._redis_connection.hget(self.__get_user_redis_key(), self.GEOCODING_SOFT_LIMIT_KEY)
|
||||
return True if soft_limit == '1' else False
|
||||
|
||||
def used_quota_month(self, year, month):
|
||||
""" Recover the used quota for the user in the current month """
|
||||
# Check for exceptions or redis timeout
|
||||
|
||||
Reference in New Issue
Block a user