Skip to content

Commit 84e3759

Browse files
committed
init
1 parent 4b1f50d commit 84e3759

File tree

3 files changed

+49
-7
lines changed

3 files changed

+49
-7
lines changed

ack_backend/src/ack_processor.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,11 @@ def lambda_handler(event, context):
4040
message_id = (incoming_message_body[0].get("row_id", "")).split("^")[0]
4141
vaccine_type = incoming_message_body[0].get("vaccine_type")
4242
supplier = incoming_message_body[0].get("supplier")
43-
supplier_queue = f"{supplier}_{vaccine_type}"
4443
created_at_formatted_string = incoming_message_body[0].get("created_at_formatted_string")
4544

4645
for message in incoming_message_body:
4746
ack_data_rows.append(convert_message_to_ack_row(message, created_at_formatted_string))
4847

49-
update_ack_file(file_key, message_id, supplier_queue, created_at_formatted_string, ack_data_rows)
48+
update_ack_file(file_key, message_id, supplier, vaccine_type, created_at_formatted_string, ack_data_rows)
5049

5150
return {"statusCode": 200, "body": json.dumps("Lambda function executed successfully!")}

ack_backend/src/logging_decorators.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,32 @@ def wrapper(message, created_at_formatted_string):
7777
return wrapper
7878

7979

80+
def upload_ack_file_logging_decorator(func):
81+
"""This decorator logs when record processing is complete."""
82+
83+
@wraps(func)
84+
def wrapper(*args, **kwargs):
85+
86+
base_log_data = {"function_name": f"ack_processor_{func.__name__}", "date_time": str(datetime.now())}
87+
start_time = time.time()
88+
89+
try:
90+
result = func(*args, **kwargs)
91+
if result is not None:
92+
message_for_logs = "Record processing complete"
93+
base_log_data.update(result)
94+
additional_log_data = {"status": "success", "statusCode": 200, "message": message_for_logs}
95+
generate_and_send_logs(start_time, base_log_data, additional_log_data)
96+
return result
97+
98+
except Exception as error:
99+
additional_log_data = {"status": "fail", "statusCode": 500, "diagnostics": str(error)}
100+
generate_and_send_logs(start_time, base_log_data, additional_log_data, is_error_log=True)
101+
raise
102+
103+
return wrapper
104+
105+
80106
def ack_lambda_handler_logging_decorator(func):
81107
"""This decorator logs the execution info for the ack lambda handler."""
82108

ack_backend/src/update_ack_file.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
import json
44
from io import StringIO, BytesIO
5-
from typing import Union
5+
from typing import Union, Optional
66
from botocore.exceptions import ClientError
77
from constants import ACK_HEADERS, SOURCE_BUCKET_NAME, ACK_BUCKET_NAME, FILE_NAME_PROC_LAMBDA_NAME
88
from audit_table import change_audit_table_status_to_processed, get_next_queued_file_details
99
from clients import s3_client, logger, lambda_client
1010
from utils_for_ack_lambda import get_row_count
11+
from logging_decorators import upload_ack_file_logging_decorator
1112

1213

1314
def create_ack_data(
@@ -65,15 +66,17 @@ def obtain_current_ack_content(temp_ack_file_key: str) -> StringIO:
6566
return accumulated_csv_content
6667

6768

69+
@upload_ack_file_logging_decorator
6870
def upload_ack_file(
6971
temp_ack_file_key: str,
7072
message_id: str,
71-
supplier_queue: str,
73+
supplier: str,
74+
vaccine_type: str,
7275
accumulated_csv_content: StringIO,
7376
ack_data_rows: list,
7477
archive_ack_file_key: str,
7578
file_key: str,
76-
) -> None:
79+
) -> Optional[dict]:
7780
"""Adds the data row to the uploaded ack file"""
7881
for row in ack_data_rows:
7982
data_row_str = [str(item) for item in row.values()]
@@ -91,17 +94,30 @@ def upload_ack_file(
9194

9295
# Update the audit table and invoke the filename lambda with next file in the queue (if one exists)
9396
change_audit_table_status_to_processed(file_key, message_id)
97+
supplier_queue = f"{supplier}_{vaccine_type}"
9498
next_queued_file_details = get_next_queued_file_details(supplier_queue)
9599
if next_queued_file_details:
96100
invoke_filename_lambda(next_queued_file_details["filename"], next_queued_file_details["message_id"])
97101

102+
# Ingestion of this file is complete
103+
result = {
104+
"message_id": message_id,
105+
"file_key": file_key,
106+
"supplier": supplier,
107+
"vaccine_type": vaccine_type,
108+
"row_count": row_count_source,
109+
}
110+
else:
111+
result = None
98112
logger.info("Ack file updated to %s: %s", ACK_BUCKET_NAME, archive_ack_file_key)
113+
return result
99114

100115

101116
def update_ack_file(
102117
file_key: str,
103118
message_id: str,
104-
supplier_queue: str,
119+
supplier: str,
120+
vaccine_type: str,
105121
created_at_formatted_string: str,
106122
ack_data_rows: list,
107123
) -> None:
@@ -113,7 +129,8 @@ def update_ack_file(
113129
upload_ack_file(
114130
temp_ack_file_key,
115131
message_id,
116-
supplier_queue,
132+
supplier,
133+
vaccine_type,
117134
accumulated_csv_content,
118135
ack_data_rows,
119136
archive_ack_file_key,

0 commit comments

Comments
 (0)