mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-21 07:51:13 -05:00
Minor tweaks to address comments on the PR
To address: - https://github.com/alphagov/notifications-api/pull/3425#discussion_r786867994 - https://github.com/alphagov/notifications-api/pull/3425#discussion_r786853329 - https://github.com/alphagov/notifications-api/pull/3425#discussion_r786848793 - https://github.com/alphagov/notifications-api/pull/3425#discussion_r786214794
This commit is contained in:
@@ -117,11 +117,11 @@ def create_nightly_notification_status_for_service_and_day(process_day, service_
|
|||||||
process_day = datetime.strptime(process_day, "%Y-%m-%d").date()
|
process_day = datetime.strptime(process_day, "%Y-%m-%d").date()
|
||||||
current_app.logger.info(
|
current_app.logger.info(
|
||||||
f'create-nightly-notification-status-for-day task started '
|
f'create-nightly-notification-status-for-day task started '
|
||||||
f'for {service_id}, {notification_type} and {process_day}'
|
f'for {service_id}, {notification_type} for {process_day}'
|
||||||
)
|
)
|
||||||
|
|
||||||
start = datetime.utcnow()
|
start = datetime.utcnow()
|
||||||
transit_data = fetch_status_data_for_service_and_day(
|
new_status_rows = fetch_status_data_for_service_and_day(
|
||||||
process_day=process_day,
|
process_day=process_day,
|
||||||
notification_type=notification_type,
|
notification_type=notification_type,
|
||||||
service_id=service_id,
|
service_id=service_id,
|
||||||
@@ -130,12 +130,12 @@ def create_nightly_notification_status_for_service_and_day(process_day, service_
|
|||||||
end = datetime.utcnow()
|
end = datetime.utcnow()
|
||||||
current_app.logger.info(
|
current_app.logger.info(
|
||||||
f'create-nightly-notification-status-for-day task fetch '
|
f'create-nightly-notification-status-for-day task fetch '
|
||||||
f'for {service_id}, {process_day} and {notification_type}: '
|
f'for {service_id}, {notification_type} for {process_day}: '
|
||||||
f'data fetched in {(end - start).seconds} seconds'
|
f'data fetched in {(end - start).seconds} seconds'
|
||||||
)
|
)
|
||||||
|
|
||||||
update_fact_notification_status(
|
update_fact_notification_status(
|
||||||
transit_data=transit_data,
|
new_status_rows=new_status_rows,
|
||||||
process_day=process_day,
|
process_day=process_day,
|
||||||
notification_type=notification_type,
|
notification_type=notification_type,
|
||||||
service_id=service_id
|
service_id=service_id
|
||||||
@@ -143,6 +143,6 @@ def create_nightly_notification_status_for_service_and_day(process_day, service_
|
|||||||
|
|
||||||
current_app.logger.info(
|
current_app.logger.info(
|
||||||
f'create-nightly-notification-status-for-day task finished '
|
f'create-nightly-notification-status-for-day task finished '
|
||||||
f'for {service_id}, {process_day} and {notification_type}: '
|
f'for {service_id}, {notification_type} for {process_day}: '
|
||||||
f'{len(transit_data)} rows updated'
|
f'{len(new_status_rows)} rows updated'
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ def fetch_status_data_for_service_and_day(process_day, service_id, notification_
|
|||||||
|
|
||||||
return db.session.query(
|
return db.session.query(
|
||||||
table.template_id,
|
table.template_id,
|
||||||
table.service_id,
|
|
||||||
func.coalesce(table.job_id, '00000000-0000-0000-0000-000000000000').label('job_id'),
|
func.coalesce(table.job_id, '00000000-0000-0000-0000-000000000000').label('job_id'),
|
||||||
table.key_type,
|
table.key_type,
|
||||||
table.status,
|
table.status,
|
||||||
@@ -58,7 +57,6 @@ def fetch_status_data_for_service_and_day(process_day, service_id, notification_
|
|||||||
table.key_type.in_((KEY_TYPE_NORMAL, KEY_TYPE_TEAM)),
|
table.key_type.in_((KEY_TYPE_NORMAL, KEY_TYPE_TEAM)),
|
||||||
).group_by(
|
).group_by(
|
||||||
table.template_id,
|
table.template_id,
|
||||||
table.service_id,
|
|
||||||
'job_id',
|
'job_id',
|
||||||
table.key_type,
|
table.key_type,
|
||||||
table.status
|
table.status
|
||||||
@@ -66,7 +64,7 @@ def fetch_status_data_for_service_and_day(process_day, service_id, notification_
|
|||||||
|
|
||||||
|
|
||||||
@autocommit
|
@autocommit
|
||||||
def update_fact_notification_status(transit_data, process_day, notification_type, service_id):
|
def update_fact_notification_status(new_status_rows, process_day, notification_type, service_id):
|
||||||
table = FactNotificationStatus.__table__
|
table = FactNotificationStatus.__table__
|
||||||
FactNotificationStatus.query.filter(
|
FactNotificationStatus.query.filter(
|
||||||
FactNotificationStatus.bst_date == process_day,
|
FactNotificationStatus.bst_date == process_day,
|
||||||
@@ -74,8 +72,9 @@ def update_fact_notification_status(transit_data, process_day, notification_type
|
|||||||
FactNotificationStatus.service_id == service_id,
|
FactNotificationStatus.service_id == service_id,
|
||||||
).delete()
|
).delete()
|
||||||
|
|
||||||
for row in transit_data:
|
for row in new_status_rows:
|
||||||
stmt = insert(table).values(
|
db.session.connection().execute(
|
||||||
|
insert(table).values(
|
||||||
bst_date=process_day,
|
bst_date=process_day,
|
||||||
template_id=row.template_id,
|
template_id=row.template_id,
|
||||||
service_id=service_id,
|
service_id=service_id,
|
||||||
@@ -85,7 +84,7 @@ def update_fact_notification_status(transit_data, process_day, notification_type
|
|||||||
notification_status=row.status,
|
notification_status=row.status,
|
||||||
notification_count=row.notification_count,
|
notification_count=row.notification_count,
|
||||||
)
|
)
|
||||||
db.session.connection().execute(stmt)
|
)
|
||||||
|
|
||||||
|
|
||||||
def fetch_notification_status_for_service_by_month(start_date, end_date, service_id):
|
def fetch_notification_status_for_service_by_month(start_date, end_date, service_id):
|
||||||
|
|||||||
Reference in New Issue
Block a user