Skip to content

Commit c42db11

Browse files
committed
Self review
1 parent eda56ab commit c42db11

File tree

4 files changed

+36
-13
lines changed

4 files changed

+36
-13
lines changed

batch_processor_filter/README.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
1-
batch-processor-filter-lambda
1+
# batch-processor-filter-lambda
22

3-
TODO
3+
## Contributing to this project
4+
You will first need to have the required setup as specified in the root README.
5+
6+
Then, getting set up to contribute to this Lambda is the same for any others. Refer to
7+
the `Setting up a virtual environment with poetry` section in the root README. Assuming 1 and 2 have already been done,
8+
then you will just need to follow steps 3-5 for this specific directory.
9+
10+
Then run:
11+
```
12+
make test
13+
```
14+
to verify your setup.
15+
16+
## Overview
17+
The context of this Lambda function should be understood within the following architecture diagram:
18+
https://nhsd-confluence.digital.nhs.uk/spaces/Vacc/pages/1161762503/Immunisation+FHIR+API+-+Batch+Ingestion+Improvements
19+
20+
The purpose of the batch-processor-filter Lambda function is to ensure that there is only ever one batch file event
21+
processing at any given time for a given combination of `supplier` + `vaccination type`. This is because the order in
22+
which updates are applied is vital; for the same supplier/vacc type combination, there may be changes to the same
23+
patient's vaccination record across 2 different files. Therefore, the order in which they arrive must be preserved.
24+
25+
The Lambda function consumes one event at a time on a per `message group id` (composed of the supplier name + vacc type)
26+
basis from an SQS FIFO queue. At a high-level, the pseudocode is as follows:
27+
28+
- check the Audit Table for any duplicate named files and process accordingly if that is the case
29+
- check the Audit Table if there is already an event processing for the given supplier + vacc type
30+
- if there is not, then update the event's status in the Audit Table and forward to SQS for processing by ECS
31+
- if there is, then throw an error so that the event is returned to the queue and will be tried again later

batch_processor_filter/src/batch_file_repository.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
class BatchFileRepository:
12-
"""Repository class to handle interactions with batch file interactions e.g. managing the source and ack files"""
12+
"""Repository class to handle interactions with batch files e.g. management of the source and ack files"""
1313
_ARCHIVE_FILE_DIR: str = "archive"
1414
_SOURCE_BUCKET_NAME: str = SOURCE_BUCKET_NAME
1515
_ACK_BUCKET_NAME: str = ACK_BUCKET_NAME
@@ -29,8 +29,8 @@ def _create_ack_failure_data(batch_file_created_event: BatchFileCreatedEvent) ->
2929
"RESPONSE_CODE": "10002",
3030
"RESPONSE_DISPLAY": "Infrastructure Level Response Value - Processing Error",
3131
"RECEIVED_TIME": batch_file_created_event["created_at_formatted_string"],
32-
"MAILBOX_FROM": "", # TODO: Leave blank for DPS, add mailbox if from mesh mailbox
33-
"LOCAL_ID": "", # TODO: Leave blank for DPS, add from ctl file if data picked up from MESH mailbox
32+
"MAILBOX_FROM": "", # VED-197 TODO: Leave blank for DPS, add mailbox if from mesh mailbox
33+
"LOCAL_ID": "", # VED-197 TODO: Leave blank for DPS, add from ctl file if data picked up from MESH mailbox
3434
"MESSAGE_DELIVERY": False,
3535
}
3636

batch_processor_filter/src/lambda_handler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
def lambda_handler(event: events.SQSEvent, _: context):
1313
event_records = event.get("Records", [])
1414

15-
# Terraform is configured so this Lambda will get a batch size of 1. We are using SQS FIFO with the message group
16-
# id set to {supplier}_{vaccine_type} so we will only want batches of 1 at a time.
17-
# Lambda will scale out to handle multiple message groups in parallel:
15+
# Terraform is configured so the Lambda will get a max batch size of 1. We are using SQS FIFO with the message group
16+
# id set to {supplier}_{vaccine_type} so it makes sense to only process batches of 1 at a time.
17+
# Lambda will scale out to handle multiple message groups in parallel so this will not block other groups:
1818
# https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/fifo-queue-lambda-behavior.html
1919
if len(event_records) != 1:
2020
raise InvalidBatchSizeError(f"Received {len(event_records)} records, expected 1")

filenameprocessor/tests/test_lambda_handler.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,6 @@ def test_lambda_handler_new_file_success_and_first_in_queue(self):
194194
self.assert_sqs_message(file_details)
195195
self.assert_no_ack_file(file_details)
196196

197-
# Reset audit table
198-
# TODO - is this needed? Check when running all
199-
# for item in self.get_audit_table_items():
200-
# dynamodb_client.delete_item(TableName=AUDIT_TABLE_NAME, Key=dict(item.items()))
201-
202197
def test_lambda_handler_non_root_file(self):
203198
"""
204199
Tests that when the file is not in the root of the source bucket, no action is taken:

0 commit comments

Comments
 (0)