Skip to content

Commit 3c614f0

Browse files
[PRMT-229] Renamed updated bulk upload workflow to performance bulk upload (#668)
1 parent e9c816c commit 3c614f0

File tree

9 files changed

+100
-26
lines changed

9 files changed

+100
-26
lines changed

.github/workflows/updated-base-run-bulk-upload.yml renamed to .github/workflows/performance-base-run-bulk-upload.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "Updated Base Bulk Upload - Execute a Bulk Upload"
1+
name: "Performance Base Bulk Upload - Execute a Bulk Upload"
22

33
permissions:
44
pull-requests: write
@@ -71,7 +71,7 @@ jobs:
7171

7272
- name: Setup Bulk Upload
7373
run: |
74-
python updated_setup_bulk_upload.py \
74+
python performance_setup_bulk_upload.py \
7575
--environment "${{ inputs.sandbox }}" \
7676
--delete-table \
7777
--download-data \
@@ -85,7 +85,7 @@ jobs:
8585

8686
- name: Run Bulk Upload
8787
run: |
88-
python run_bulk_upload.py \
88+
python performance_run_bulk_upload.py \
8989
--environment "${{ inputs.sandbox }}" \
9090
--start-bulk-upload
9191
working-directory: ./tests/bulk-upload/scripts

.github/workflows/updated-run-bulk-upload-test.yml renamed to .github/workflows/performance-run-bulk-upload-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Updated Run Bulk Upload - Test
1+
name: Performance Run Bulk Upload - Test
22

33
permissions:
44
pull-requests: write
@@ -31,7 +31,7 @@ on:
3131

3232
jobs:
3333
bulk_upload:
34-
uses: ./.github/workflows/updated-base-run-bulk-upload.yml
34+
uses: ./.github/workflows/performance-base-run-bulk-upload.yml
3535
with:
3636
environment: development
3737
sandbox: "${{ inputs.sandbox }}"

lambdas/handlers/bulk_upload_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def lambda_handler(event, _context):
2727
validation_strict_mode = validation_strict_mode_flag_object[
2828
FeatureFlags.LLOYD_GEORGE_VALIDATION_STRICT_MODE_ENABLED.value
2929
]
30-
pds_fhir_always_true = os.getenv("PDS_FHIR_ALWAYS_TRUE", "false").lower() == "true"
30+
bypass_pds = os.getenv("BYPASS_PDS", "false").lower() == "true"
3131

3232
if validation_strict_mode:
3333
logger.info("Lloyd George validation strict mode is enabled")
@@ -43,7 +43,7 @@ def lambda_handler(event, _context):
4343
).create_api_gateway_response()
4444

4545
bulk_upload_service = BulkUploadService(
46-
strict_mode=validation_strict_mode, pds_fhir_always_true=pds_fhir_always_true
46+
strict_mode=validation_strict_mode, bypass_pds=bypass_pds
4747
)
4848

4949
try:

lambdas/services/bulk_upload_service.py

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

5151

5252
class BulkUploadService:
53-
def __init__(self, strict_mode, pds_fhir_always_true=False):
53+
def __init__(self, strict_mode, bypass_pds=False):
5454
self.dynamo_repository = BulkUploadDynamoRepository()
5555
self.sqs_repository = BulkUploadSqsRepository()
5656
self.bulk_upload_s3_repository = BulkUploadS3Repository()
@@ -59,7 +59,7 @@ def __init__(self, strict_mode, pds_fhir_always_true=False):
5959
self.unhandled_messages = []
6060
self.file_path_cache = {}
6161
self.pdf_stitching_queue_url = os.environ["PDF_STITCHING_SQS_URL"]
62-
self.pds_fhir_always_true = pds_fhir_always_true
62+
self.bypass_pds = bypass_pds
6363

6464
def process_message_queue(self, records: list):
6565
for index, message in enumerate(records, start=1):
@@ -137,7 +137,7 @@ def handle_sqs_message(self, message: dict):
137137
patient_ods_code = (
138138
pds_patient_details.get_ods_code_or_inactive_status_for_gp()
139139
)
140-
if not self.pds_fhir_always_true:
140+
if not self.bypass_pds:
141141
if not self.strict_mode:
142142
(
143143
name_validation_accepted_reason,

lambdas/utils/utilities.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def get_pds_service() -> PatientSearch:
7474
return PdsApiService(ssm_service, auth_service)
7575
else:
7676
return MockPdsApiService(
77-
always_pass_mock=os.getenv("PDS_FHIR_ALWAYS_TRUE") in ["True", "true"]
77+
always_pass_mock=os.getenv("BYPASS_PDS", "false").lower() == "true"
7878
)
7979

8080

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import argparse
2+
import json
3+
import sys
4+
5+
import boto3
6+
7+
8+
def invoke_lambda(lambda_name, payload={}):
9+
client = boto3.client("lambda")
10+
response = client.invoke(
11+
FunctionName=lambda_name,
12+
InvocationType="RequestResponse",
13+
Payload=json.dumps(payload),
14+
)
15+
return json.loads(response["Payload"].read())
16+
17+
18+
def update_lambda_environment_variables(lambda_name, new_variables):
19+
session = boto3.Session()
20+
lambda_client = session.client("lambda")
21+
22+
response = lambda_client.get_function_configuration(FunctionName=lambda_name)
23+
current_environment = response["Environment"]["Variables"]
24+
25+
updated_environment = current_environment.copy()
26+
updated_environment.update(new_variables)
27+
28+
lambda_client.update_function_configuration(
29+
FunctionName=lambda_name, Environment={"Variables": updated_environment}
30+
)
31+
32+
33+
if __name__ == "__main__":
34+
parser = argparse.ArgumentParser(description="Run Bulk Upload Script")
35+
36+
parser.add_argument(
37+
"--environment",
38+
help="The name of the environment",
39+
)
40+
parser.add_argument(
41+
"--disable-pds-stub",
42+
action="store_true",
43+
help="Disable the PDS Stub",
44+
)
45+
parser.add_argument(
46+
"--start-bulk-upload",
47+
action="store_true",
48+
help="Start the Bulk Upload",
49+
)
50+
51+
args = parser.parse_args()
52+
53+
if not args.environment:
54+
args.environment = input("Please enter the name of the environment: ")
55+
56+
bulk_upload_lambda_name = f"{args.environment}_BulkUploadLambda"
57+
search_lambda_name = f"{args.environment}_SearchPatientDetailsLambda"
58+
if args.disable_pds_stub or (
59+
sys.stdin.isatty()
60+
and input("Would you like to disable the FHIR Stub: ").lower() == "y"
61+
):
62+
new_variables = {"PDS_FHIR_IS_STUBBED": "false"}
63+
update_lambda_environment_variables(bulk_upload_lambda_name, new_variables)
64+
update_lambda_environment_variables(search_lambda_name, new_variables)
65+
else:
66+
new_variables = {"PDS_FHIR_IS_STUBBED": "true", "BYPASS_PDS": "true"}
67+
update_lambda_environment_variables(bulk_upload_lambda_name, new_variables)
68+
update_lambda_environment_variables(search_lambda_name, new_variables)
69+
if args.start_bulk_upload or input(
70+
"Would you like to start the Bulk Upload Process:"
71+
):
72+
invoke_lambda(f"{args.environment}_BulkUploadMetadataLambda")

tests/bulk-upload/scripts/updated_setup_bulk_upload.py renamed to tests/bulk-upload/scripts/performance_setup_bulk_upload.py

File renamed without changes.

tests/bulk-upload/scripts/run_bulk_upload.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ def invoke_lambda(lambda_name, payload={}):
3535
if args.start_bulk_upload or input(
3636
"Would you like to start the Bulk Upload Process:"
3737
):
38-
invoke_lambda(f"{args.environment}_BulkUploadMetadataLambda")
38+
invoke_lambda(f"{args.environment}_BulkUploadMetadataLambda")

tests/bulk-upload/scripts/test_updated_setup_bulk_upload.py renamed to tests/bulk-upload/scripts/test_performance_setup_bulk_upload.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from unittest.mock import patch
66

77
import pytest
8-
from updated_setup_bulk_upload import (
8+
from performance_setup_bulk_upload import (
99
S3_STORAGE_CLASS,
1010
STAGING_BUCKET,
1111
build_file_path,
@@ -58,7 +58,7 @@ def test_generate_nhs_number(
5858
mocker, input_nhs_number, mock_return_values, expected_output
5959
):
6060
mocker.patch(
61-
"updated_setup_bulk_upload.pairing_nhs_number_digit",
61+
"performance_setup_bulk_upload.pairing_nhs_number_digit",
6262
side_effect=mock_return_values,
6363
)
6464
result = generate_nhs_number(input_nhs_number)
@@ -123,20 +123,20 @@ def test_build_file_path(nhs_number, file_name, expected):
123123

124124
def test_create_test_file_keys_and_metadata_rows_calls(mocker):
125125
mock_generate_random_name = mocker.patch(
126-
"updated_setup_bulk_upload.generate_random_name", return_value="Alice"
126+
"performance_setup_bulk_upload.generate_random_name", return_value="Alice"
127127
)
128128
mock_generate_nhs_number = mocker.patch(
129-
"updated_setup_bulk_upload.generate_nhs_number",
129+
"performance_setup_bulk_upload.generate_nhs_number",
130130
side_effect=lambda number: number + "1",
131131
)
132132
mock_generate_file_name = mocker.patch(
133-
"updated_setup_bulk_upload.generate_file_name", return_value="file1.pdf"
133+
"performance_setup_bulk_upload.generate_file_name", return_value="file1.pdf"
134134
)
135135
mock_build_file_path = mocker.patch(
136-
"updated_setup_bulk_upload.build_file_path", return_value="NH123/file1.pdf"
136+
"performance_setup_bulk_upload.build_file_path", return_value="NH123/file1.pdf"
137137
)
138138
mock_build_metadata_csv_row = mocker.patch(
139-
"updated_setup_bulk_upload.build_metadata_csv_row", return_value="row"
139+
"performance_setup_bulk_upload.build_metadata_csv_row", return_value="row"
140140
)
141141

142142
requested_patients_number = 2
@@ -186,11 +186,13 @@ def test_upload_source_file_to_staging_calls(mocker):
186186
)
187187
file_key = "1234567890/test.pdf"
188188

189-
mock_client = mocker.patch("updated_setup_bulk_upload.client")
190-
mocker.patch("updated_setup_bulk_upload.STAGING_BUCKET", "test-bucket")
191-
mocker.patch("updated_setup_bulk_upload.S3_STORAGE_CLASS", "INTELLIGENT_TIERING")
189+
mock_client = mocker.patch("performance_setup_bulk_upload.client")
190+
mocker.patch("performance_setup_bulk_upload.STAGING_BUCKET", "test-bucket")
192191
mocker.patch(
193-
"updated_setup_bulk_upload.S3_SCAN_TAGS",
192+
"performance_setup_bulk_upload.S3_STORAGE_CLASS", "INTELLIGENT_TIERING"
193+
)
194+
mocker.patch(
195+
"performance_setup_bulk_upload.S3_SCAN_TAGS",
194196
[{"Key": "ScanStatus", "Value": "Clean"}],
195197
)
196198

@@ -203,15 +205,15 @@ def test_upload_source_file_to_staging_calls(mocker):
203205
def test_delete_file_from_staging_calls_client_delete_object_once():
204206
file_key = "some/file/key.pdf"
205207

206-
with patch("updated_setup_bulk_upload.client") as mock_client:
208+
with patch("performance_setup_bulk_upload.client") as mock_client:
207209
delete_file_from_staging(file_key)
208210

209211
calls = mock_client.delete_object.call_count
210212
assert calls == 1, f"Expected 1 call to delete_object, got {calls}"
211213

212214

213215
def test_upload_lg_files_to_staging_calls_client_methods(mocker):
214-
mock_client = mocker.patch("updated_setup_bulk_upload.client")
216+
mock_client = mocker.patch("performance_setup_bulk_upload.client")
215217

216218
lg_file_keys = ["file1.pdf", "file2.pdf", "file3.pdf"]
217219
source_pdf_file_key = "source.pdf"
@@ -302,7 +304,7 @@ def test_build_metadata_csv_row():
302304
def test_upload_metadata_to_s3_calls_put_object_with_correct_args(mocker):
303305
test_body = "some,csv,content\n1,2,3"
304306

305-
mock_client = mocker.patch("updated_setup_bulk_upload.client")
307+
mock_client = mocker.patch("performance_setup_bulk_upload.client")
306308

307309
upload_metadata_to_s3(test_body)
308310

0 commit comments

Comments
 (0)