2019-06-11 13:57:17 +01:00
|
|
|
from datetime import timedelta
|
2017-08-30 14:36:16 +01:00
|
|
|
|
|
|
|
|
from flask import current_app
|
|
|
|
|
|
2021-02-22 15:42:29 +00:00
|
|
|
from app.dao.fact_processing_time_dao import insert_update_processing_time
|
|
|
|
|
from app.models import FactProcessingTime
|
2019-06-11 13:57:17 +01:00
|
|
|
from app.utils import get_london_midnight_in_utc
|
2017-08-31 11:10:54 +01:00
|
|
|
from app.dao.notifications_dao import dao_get_total_notifications_sent_per_day_for_performance_platform
|
2017-08-30 14:36:16 +01:00
|
|
|
from app import performance_platform_client
|
|
|
|
|
|
|
|
|
|
|
2019-06-11 13:57:17 +01:00
|
|
|
def send_processing_time_to_performance_platform(bst_date):
|
|
|
|
|
start_time = get_london_midnight_in_utc(bst_date)
|
|
|
|
|
end_time = get_london_midnight_in_utc(bst_date + timedelta(days=1))
|
2017-08-30 14:36:16 +01:00
|
|
|
|
2021-02-22 15:42:29 +00:00
|
|
|
send_processing_time_for_start_and_end(start_time, end_time, bst_date)
|
2017-08-31 14:29:13 +01:00
|
|
|
|
|
|
|
|
|
2021-02-22 15:42:29 +00:00
|
|
|
def send_processing_time_for_start_and_end(start_time, end_time, bst_date):
|
2019-04-02 11:49:20 +01:00
|
|
|
result = dao_get_total_notifications_sent_per_day_for_performance_platform(start_time, end_time)
|
2017-08-30 14:36:16 +01:00
|
|
|
|
|
|
|
|
current_app.logger.info(
|
|
|
|
|
'Sending processing-time to performance platform for date {}. Total: {}, under 10 secs {}'.format(
|
2019-04-02 11:49:20 +01:00
|
|
|
start_time, result.messages_total, result.messages_within_10_secs
|
2017-08-30 14:36:16 +01:00
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
2019-04-02 11:49:20 +01:00
|
|
|
send_processing_time_data(start_time, 'messages-total', result.messages_total)
|
|
|
|
|
send_processing_time_data(start_time, 'messages-within-10-secs', result.messages_within_10_secs)
|
2021-02-22 15:42:29 +00:00
|
|
|
insert_update_processing_time(FactProcessingTime(
|
|
|
|
|
bst_date=bst_date,
|
|
|
|
|
messages_total=result.messages_total,
|
|
|
|
|
messages_within_10_secs=result.messages_within_10_secs)
|
|
|
|
|
)
|
2017-08-30 14:36:16 +01:00
|
|
|
|
|
|
|
|
|
2019-04-02 11:49:20 +01:00
|
|
|
def send_processing_time_data(start_time, status, count):
|
2017-08-30 14:36:16 +01:00
|
|
|
payload = performance_platform_client.format_payload(
|
|
|
|
|
dataset='processing-time',
|
2019-04-02 11:49:20 +01:00
|
|
|
start_time=start_time,
|
2017-08-30 14:36:16 +01:00
|
|
|
group_name='status',
|
|
|
|
|
group_value=status,
|
|
|
|
|
count=count
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
performance_platform_client.send_stats_to_performance_platform(payload)
|