notify-300 set total message limit of 250k

This commit is contained in:
Kenneth Kehl
2023-04-28 12:37:06 -07:00
parent 5cbeedb000
commit 9de806000a
14 changed files with 193 additions and 89 deletions

View File

@@ -5,6 +5,7 @@ from notifications_utils.clients.redis import (
daily_limit_cache_key,
daily_total_cache_key,
rate_limit_cache_key,
total_limit_cache_key,
)
from notifications_utils.recipients import (
get_international_phone_info,
@@ -74,6 +75,26 @@ def check_service_over_daily_message_limit(key_type, service):
return int(service_stats)
def check_service_over_total_message_limit(key_type, service):
if key_type == KEY_TYPE_TEST or not current_app.config['REDIS_ENABLED']:
return 0
cache_key = total_limit_cache_key(service.id)
service_stats = redis_store.get(cache_key)
if service_stats is None:
# first message of the day, set the cache to 0 and the expiry to 24 hours
service_stats = 0
redis_store.set(cache_key, service_stats, ex=86400)
return service_stats
if int(service_stats) >= service.total_message_limit:
current_app.logger.info(
"service {} has been rate limited for total use sent {} limit {}".format(
service.id, int(service_stats), service.total_message_limit)
)
raise TooManyRequestsError(service.total_message_limit)
return int(service_stats)
def check_application_over_daily_message_total(key_type, service):
if key_type == KEY_TYPE_TEST or not current_app.config['REDIS_ENABLED']:
return 0