mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-05 02:41:14 -05:00
fix message ratio endpoint
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import itertools
|
||||
from datetime import datetime, timedelta
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
from flask import Blueprint, current_app, jsonify, request
|
||||
from sqlalchemy import select
|
||||
@@ -7,7 +8,7 @@ from sqlalchemy.exc import IntegrityError
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
from werkzeug.datastructures import MultiDict
|
||||
|
||||
from app import db, redis_store
|
||||
from app import db
|
||||
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
|
||||
@@ -28,7 +29,10 @@ from app.dao.fact_notification_status_dao import (
|
||||
fetch_stats_for_all_services_by_date_range,
|
||||
)
|
||||
from app.dao.inbound_numbers_dao import dao_allocate_number_for_service
|
||||
from app.dao.notifications_dao import dao_get_notification_count_for_service
|
||||
from app.dao.notifications_dao import (
|
||||
dao_get_notification_count_for_service,
|
||||
dao_get_notification_count_for_service_message_ratio,
|
||||
)
|
||||
from app.dao.organization_dao import dao_get_organization_by_service_id
|
||||
from app.dao.service_data_retention_dao import (
|
||||
fetch_service_data_retention,
|
||||
@@ -109,7 +113,6 @@ 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__)
|
||||
|
||||
@@ -1145,17 +1148,11 @@ def modify_service_data_retention(service_id, data_retention_id):
|
||||
def get_service_message_ratio():
|
||||
service_id = request.args.get("service_id")
|
||||
|
||||
current_year = datetime.datetime.now(tzinfo=ZoneInfo("UTC")).year
|
||||
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)
|
||||
messages_sent = dao_get_notification_count_for_service_message_ratio(
|
||||
service_id, current_year
|
||||
)
|
||||
|
||||
return {
|
||||
"messages_sent": messages_sent,
|
||||
|
||||
Reference in New Issue
Block a user