Move notification retrieval logic into perf platform client and dont filter by status

This commit is contained in:
Imdad Ahad
2017-01-27 16:39:01 +00:00
parent c87d0a37f3
commit cc7bf45766
6 changed files with 79 additions and 104 deletions

View File

@@ -22,15 +22,11 @@ from app.models import (
NOTIFICATION_PENDING,
NOTIFICATION_TECHNICAL_FAILURE,
NOTIFICATION_TEMPORARY_FAILURE,
NOTIFICATION_STATUS_TYPES_COMPLETED,
KEY_TYPE_NORMAL, KEY_TYPE_TEST
)
from app.dao.dao_utils import transactional
from app.statsd_decorators import statsd
from app.utils import (
get_midnight_for_day_before,
get_london_midnight_in_utc)
def dao_get_notification_statistics_for_service_and_day(service_id, day):
@@ -419,27 +415,9 @@ def get_total_sent_notifications_in_date_range(start_date, end_date, notificatio
func.count(NotificationHistory.id).label('count')
).filter(
NotificationHistory.key_type != KEY_TYPE_TEST,
NotificationHistory.status.in_(NOTIFICATION_STATUS_TYPES_COMPLETED),
NotificationHistory.created_at >= start_date,
NotificationHistory.created_at <= end_date,
NotificationHistory.notification_type == notification_type
).first()
).scalar()
return 0 if result is None else result.count
def get_total_sent_notifications_yesterday():
today = datetime.utcnow()
start_date = get_midnight_for_day_before(today)
end_date = get_london_midnight_in_utc(today)
return {
"start_date": start_date,
"end_date": end_date,
"email": {
"count": get_total_sent_notifications_in_date_range(start_date, end_date, 'email')
},
"sms": {
"count": get_total_sent_notifications_in_date_range(start_date, end_date, 'sms')
}
}
return result or 0