55
66from app import db
77from app .aws .s3 import (
8+ extract_personalisation ,
9+ extract_phones ,
10+ get_job_from_s3 ,
811 get_job_metadata_from_s3 ,
912 get_personalisation_from_s3 ,
1013 get_phone_number_from_s3 ,
3639 notification_with_template_schema ,
3740 notifications_filter_schema ,
3841)
39- from app .utils import check_suspicious_id , midnight_n_days_ago , pagination_links
42+ from app .utils import check_suspicious_id , hilite , midnight_n_days_ago , pagination_links
4043
4144job_blueprint = Blueprint ("job" , __name__ , url_prefix = "/service/<uuid:service_id>/job" )
4245
4649
4750@job_blueprint .route ("/<job_id>" , methods = ["GET" ])
4851def get_job_by_service_and_job_id (service_id , job_id ):
52+ current_app .logger .info (hilite ("ENTER get_job_by_service_and_job_id" ))
4953 check_suspicious_id (service_id , job_id )
5054 job = dao_get_job_by_service_id_and_job_id (service_id , job_id )
5155 statistics = dao_get_notification_outcomes_for_job (service_id , job_id )
@@ -71,8 +75,12 @@ def cancel_job(service_id, job_id):
7175
7276@job_blueprint .route ("/<job_id>/notifications" , methods = ["GET" ])
7377def get_all_notifications_for_service_job (service_id , job_id ):
78+
7479 check_suspicious_id (service_id , job_id )
7580
81+ job = get_job_from_s3 (service_id , job_id )
82+ phones = extract_phones (job , service_id , job_id )
83+ personalisation = extract_personalisation (job )
7684 data = notifications_filter_schema .load (request .args )
7785 page = data ["page" ] if "page" in data else 1
7886 page_size = (
@@ -90,21 +98,13 @@ def get_all_notifications_for_service_job(service_id, job_id):
9098
9199 for notification in paginated_notifications .items :
92100 if notification .job_id is not None :
93- recipient = get_phone_number_from_s3 (
94- notification .service_id ,
95- notification .job_id ,
96- notification .job_row_number ,
97- )
101+ recipient = phones [notification .job_row_number ]
98102 notification .to = recipient
99103 notification .normalised_to = recipient
100104
101105 for notification in paginated_notifications .items :
102106 if notification .job_id is not None :
103- notification .personalisation = get_personalisation_from_s3 (
104- notification .service_id ,
105- notification .job_id ,
106- notification .job_row_number ,
107- )
107+ notification .personalisation = personalisation [notification .job_row_number ]
108108
109109 notifications = None
110110 if data .get ("format_for_csv" ):
@@ -116,6 +116,7 @@ def get_all_notifications_for_service_job(service_id, job_id):
116116 notifications = notification_with_template_schema .dump (
117117 paginated_notifications .items , many = True
118118 )
119+ current_app .logger .info (hilite ("Got the dumped notifications and returning" ))
119120
120121 return (
121122 jsonify (
@@ -134,6 +135,8 @@ def get_all_notifications_for_service_job(service_id, job_id):
134135
135136@job_blueprint .route ("/<job_id>/recent_notifications" , methods = ["GET" ])
136137def get_recent_notifications_for_service_job (service_id , job_id ):
138+
139+ current_app .logger .info (hilite ("ENTER get_recent_notifications_for_service_job" ))
137140 check_suspicious_id (service_id , job_id )
138141
139142 data = notifications_filter_schema .load (request .args )
@@ -220,7 +223,9 @@ def get_jobs_by_service(service_id):
220223 else :
221224 limit_days = None
222225
223- use_processing_time = request .args .get ("use_processing_time" , "false" ).lower () == "true"
226+ use_processing_time = (
227+ request .args .get ("use_processing_time" , "false" ).lower () == "true"
228+ )
224229
225230 valid_statuses = set (JobStatus )
226231 statuses_arg = request .args .get ("statuses" , "" )
@@ -332,6 +337,8 @@ def get_paginated_jobs(
332337 statuses ,
333338 page ,
334339):
340+
341+ current_app .logger .info (hilite ("ENTER get_paginated_jobs" ))
335342 pagination = dao_get_jobs_by_service_id (
336343 service_id ,
337344 limit_days = limit_days ,
0 commit comments