-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* prmdr-242 create name validtions * prmdr-242 added more validation and test * prmdr-242 refactor validtion service and add unit test * prmdr-242 test-fix * prmdr-242 change regex * prmdr-242 Pr changes * allowing special characters to regex * added test for allowing special char * added model for metadata * [PRMDR-336] Add csv_to_staging_metadata to lambda Co-authored-by: NogaNHS <noga.sasson1@nhs.net> * add lambda to workflow * [PRMDR-336] Add unit test for lambda, tested lambda with sandbox * [PRMDR-336] Substitute expected sqs msg in test with .json file * run formatter * [PRMDR-336] Setup configdict and alias in pydantic model to support serialise/deserialise with field names in NHS spec * [PRMDR-336] Add unit test for sqs service * [PRMDR-336] Add logging, run formatter * [PRMDR-336] Remove unneccesary file * [PRMDR-336] Add lambda deploy to github action yml * [PRMDR-336] Add lambda deploy to dev-to-main github action yml * [PRMDR-336] Remove a redundant str() call * [PRMDR-338] Add bulk_upload_handler lambda, amend StagingMetadata model, add basic test for serialise/deserialise for StagingMetadata * (WIP) [PRMDR-338] Add bulk upload service * [PRMDR-338] Refactoring * [PRMDR-338] Start bringing in LG file validation from other branch * [PRMDR-338] Adding unit test for bulk upload service * [PRMDR-338] Run formatter * [PRMDR-338] Continue adding unit tests * [PRMDR-338] run formatter * [PRMDR-338] Adding unit test to bulk upload service * [PRMDR-338] Rename the file for test data * [PRMDR-338] Add unit test for new methods in S3 service * [PRMDR-338] Add unit tests for bulk_upload_handler * [PRMDR-338] Remove duplicated code * Run formatter * [PRMDR-338] Add new lambda to github action yml * [PRMDR-338] Add unit test for added validation in lloyd_george_validator * [PRMDR-338] Fix issue around sqs message attribute, add unit test for extract_info_from_filename * Run formatter * [PRMDR-338] Revert accidental deletion of some unit tests for bulk_upload_metadata lambda * [PRMDR-338] Amend a unit test for bulk_upload_service * run formatter --------- Co-authored-by: NogaNHS <noga.sasson1@nhs.net>
- Loading branch information
1 parent
cef4c71
commit aaaa996
Showing
27 changed files
with
945 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import json | ||
import logging | ||
import os | ||
|
||
from services.bulk_upload_service import BulkUploadService | ||
from services.lloyd_george_validator import LGInvalidFilesException | ||
from services.sqs_service import SQSService | ||
from utils.exceptions import InvalidMessageException | ||
|
||
logger = logging.getLogger() | ||
logger.setLevel(logging.INFO) | ||
|
||
|
||
def lambda_handler(event, _context): | ||
logger.info("Received event. Starting bulk upload process") | ||
bulk_upload_service = BulkUploadService() | ||
|
||
if "Records" not in event: | ||
logger.error(f"No sqs messages found in event: {event}. Will ignore this event") | ||
return | ||
|
||
for index, message in enumerate(event["Records"], start=1): | ||
try: | ||
logger.info(f"Processing message {index} of {len(event['Records'])}") | ||
bulk_upload_service.handle_sqs_message(message) | ||
except (InvalidMessageException, LGInvalidFilesException) as error: | ||
handle_invalid_message(invalid_message=message, error=error) | ||
|
||
|
||
def handle_invalid_message(invalid_message: dict, error=None): | ||
# Currently we just send the invalid message to invalid queue. | ||
# In future ticket, will change this to record errors in dynamo db | ||
invalid_queue_url = os.environ["INVALID_SQS_QUEUE_URL"] | ||
sqs_service = SQSService() | ||
|
||
new_message = {"original_message": invalid_message["body"]} | ||
if error: | ||
new_message["error"] = str(error) | ||
|
||
try: | ||
nhs_number = invalid_message["messageAttributes"]["NhsNumber"]["stringValue"] | ||
except KeyError: | ||
nhs_number = "" | ||
|
||
sqs_service.send_message_with_nhs_number_attr( | ||
queue_url=invalid_queue_url, | ||
message_body=json.dumps(new_message), | ||
nhs_number=nhs_number, | ||
) | ||
logger.info(f"Sent message to invalid queue: {invalid_message}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.