mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-12 16:22:17 -05:00
add api for message limit, messages_sent
This commit is contained in:
@@ -22,28 +22,20 @@ from notifications_utils.recipients import (
|
||||
|
||||
|
||||
def check_service_over_total_message_limit(key_type, service):
|
||||
print(hilite("ENTER check_service_over_total_message_limit"))
|
||||
if key_type == KeyType.TEST or not current_app.config["REDIS_ENABLED"]:
|
||||
return 0
|
||||
|
||||
cache_key = total_limit_cache_key(service.id)
|
||||
print(hilite(f"CACHE_KEY = {cache_key}"))
|
||||
service_stats = redis_store.get(cache_key)
|
||||
|
||||
# Originally this was a daily limit check. It is now a free-tier limit check.
|
||||
# TODO is this annual or forever for each service?
|
||||
# TODO do we need a way to clear this out? How do we determine if it is
|
||||
# free-tier or paid? What are the limits for paid? Etc.
|
||||
# TODO
|
||||
# setting expiration to one year for now on the assume that the free tier
|
||||
# limit resets annually.
|
||||
|
||||
# add column for actual charges to notifications and notifification_history table
|
||||
# add service api to return total_message_limit and actual number of messages for service
|
||||
# For now we are using calendar year
|
||||
# Switch to using service agreement dates when the Agreement model is ready
|
||||
if service_stats is None:
|
||||
service_stats = 0
|
||||
redis_store.set(cache_key, service_stats, ex=365 * 24 * 60 * 60)
|
||||
return service_stats
|
||||
# TODO CHANGE THIS BACK TO SERVICE TOTAL MESSAGE LIMIT
|
||||
if int(service_stats) >= 5:
|
||||
# if int(service_stats) >= service.total_message_limit:
|
||||
current_app.logger.warning(
|
||||
|
||||
@@ -7,7 +7,7 @@ from sqlalchemy.exc import IntegrityError
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
from werkzeug.datastructures import MultiDict
|
||||
|
||||
from app import db
|
||||
from app import db, redis_store
|
||||
from app.aws.s3 import get_personalisation_from_s3, get_phone_number_from_s3
|
||||
from app.config import QueueNames
|
||||
from app.dao import fact_notification_status_dao, notifications_dao
|
||||
@@ -109,6 +109,7 @@ from app.service.service_senders_schema import (
|
||||
from app.service.utils import get_guest_list_objects
|
||||
from app.user.users_schema import post_set_permissions_schema
|
||||
from app.utils import get_prev_next_pagination_links, utc_now
|
||||
from notifications_utils.clients.redis import total_limit_cache_key
|
||||
|
||||
service_blueprint = Blueprint("service", __name__)
|
||||
|
||||
@@ -1120,6 +1121,28 @@ def modify_service_data_retention(service_id, data_retention_id):
|
||||
return "", 204
|
||||
|
||||
|
||||
@service_blueprint.route("/get-service-message-ratio")
|
||||
def get_service_message_ratio():
|
||||
service_id = request.args.get("service_id")
|
||||
|
||||
my_service = dao_fetch_service_by_id(service_id)
|
||||
|
||||
cache_key = total_limit_cache_key(service_id)
|
||||
messages_sent = redis_store.get(cache_key)
|
||||
if messages_sent is None:
|
||||
messages_sent = 0
|
||||
current_app.logger.warning(
|
||||
f"Messages sent was not being tracked for service {service_id}"
|
||||
)
|
||||
else:
|
||||
messages_sent = int(messages_sent)
|
||||
|
||||
return {
|
||||
"messages_sent": messages_sent,
|
||||
"total_message_limit": my_service.total_message_limit,
|
||||
}
|
||||
|
||||
|
||||
@service_blueprint.route("/monthly-data-by-service")
|
||||
def get_monthly_notification_data_by_service():
|
||||
start_date = request.args.get("start_date")
|
||||
|
||||
Reference in New Issue
Block a user