Skip to content

Commit e506186

Browse files
committed
IdSyncException
1 parent feaebd0 commit e506186

File tree

13 files changed

+287
-200
lines changed

13 files changed

+287
-200
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
SHELL=/usr/bin/env bash -euo pipefail
22

3-
PYTHON_PROJECT_DIRS_WITH_UNIT_TESTS = ack_backend backend delta_backend filenameprocessor mesh_processor recordprocessor redis_sync
3+
PYTHON_PROJECT_DIRS_WITH_UNIT_TESTS = ack_backend backend delta_backend filenameprocessor mesh_processor recordprocessor redis_sync lamdas/id_sync
44
PYTHON_PROJECT_DIRS = e2e e2e_batch $(PYTHON_PROJECT_DIRS_WITH_UNIT_TESTS)
55

66
#Installs dependencies using poetry.

azure/templates/deploy-stage.yml

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ parameters:
1616
default: ''
1717
- name: proxy_path
1818
type: string
19-
default: 'internal-dev'
19+
default: 'internal-dev'
2020
- name: secret_file_ids
2121
type: object
2222
default: []
@@ -150,10 +150,44 @@ jobs:
150150
echo "##vso[task.setvariable variable=FULLY_QUALIFIED_SERVICE_NAME]${FULLY_QUALIFIED_SERVICE_NAME}"
151151
fi
152152
displayName: Override FULLY_QUALIFIED_SERVICE_NAME
153-
154153
- checkout: self
155154
path: "s/${{ parameters.service_name }}"
156-
submodules: true
155+
submodules: recursive
156+
fetchDepth: 0 # Ensure complete history is fetched for submodules
157+
# Add this step after checkout and before terraform
158+
- task: Bash@3
159+
displayName: 'Debug Azure DevOps Structure'
160+
inputs:
161+
targetType: 'inline'
162+
script: |
163+
echo "=== SAW AZURE DEVOPS WORKSPACE DEBUG ==="
164+
echo "Pipeline.Workspace: $(Pipeline.Workspace)"
165+
echo "Build.SourcesDirectory: $(Build.SourcesDirectory)"
166+
echo "System.DefaultWorkingDirectory: $(System.DefaultWorkingDirectory)"
167+
echo "Agent.BuildDirectory: $(Agent.BuildDirectory)"
168+
echo "Current directory: $(pwd)"
169+
echo ""
170+
echo "=== WORKSPACE CONTENTS ==="
171+
echo "Pipeline workspace contents:"
172+
find $(Pipeline.Workspace) -maxdepth 3 -type d 2>/dev/null | head -20
173+
echo ""
174+
echo "=== SOURCE DIRECTORY CONTENTS ==="
175+
echo "Build sources directory contents:"
176+
ls -la $(Build.SourcesDirectory) 2>/dev/null || echo "Build.SourcesDirectory not accessible"
177+
echo ""
178+
echo "=== CURRENT DIRECTORY TREE ==="
179+
echo "Current directory tree:"
180+
find . -maxdepth 3 -type d 2>/dev/null || echo "Cannot access current directory"
181+
echo ""
182+
echo "=== SEARCH FOR LAMBDAS ==="
183+
echo "Searching for lambdas directory:"
184+
find $(Pipeline.Workspace) -name "lambdas" -type d 2>/dev/null || echo "No lambdas directory found"
185+
echo ""
186+
echo "=== SEARCH FOR DOCKERFILES ==="
187+
echo "Searching for Dockerfiles:"
188+
find $(Pipeline.Workspace) -name "*.Dockerfile" -type f 2>/dev/null || echo "No Dockerfiles found"
189+
echo "=== END DEBUG ==="
190+
157191
158192
- task: UsePythonVersion@0
159193
displayName: "Use Python ${{ parameters.python_version }}"
@@ -174,4 +208,4 @@ jobs:
174208
parameters:
175209
state: failure
176210
on_failure: true
177-
description: "Deploy failed"
211+
description: "Deploy failed"

delta_backend/src/delta.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from log_firehose import FirehoseLogger
1616

1717
failure_queue_url = os.environ["AWS_SQS_QUEUE_URL"]
18-
ieds_table_name = os.environ["IEDS_TABLE_NAME"]
1918
delta_table_name = os.environ["DELTA_TABLE_NAME"]
2019
delta_source = os.environ["SOURCE"]
2120
region_name = "eu-west-2"

lambdas/id_sync.Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ RUN mkdir -p /home/appuser && \
77
chown -R 1001:1001 /home/appuser && pip install "poetry~=1.5.0"
88

99
# Install Poetry dependencies
10-
# Copy shared Poetry files first
11-
COPY shared/poetry.lock shared/pyproject.toml shared/README.md ./shared/
1210
# Copy id_sync Poetry files
1311
COPY id_sync/poetry.lock id_sync/pyproject.toml id_sync/README.md ./
12+
# Copy shared/src/common to ./src/common
13+
COPY shared/src/common ./src/common
14+
15+
RUN echo "Listing /var/task after source code copy:" && ls -R /var/task
1416

1517
# Install id_sync dependencies
1618
WORKDIR /var/task
@@ -35,4 +37,4 @@ RUN chmod 644 $(find . -type f) && chmod 755 $(find . -type d)
3537
USER 1001:1001
3638

3739
# Set the Lambda handler
38-
CMD ["id_sync.handler"]
40+
CMD ["id_sync.handler"]

lambdas/id_sync/src/id_sync.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,21 @@
33
from common.log_decorator import logging_decorator
44
from common.aws_lambda_event import AwsLambdaEvent
55
from record_processor import process_record
6+
import json
67
'''
78
Lambda function handler for processing SQS events.Lambda for ID Sync. Fired by SQS
89
'''
910

1011

12+
class IdSyncException(Exception):
13+
"""Custom exception for ID Sync errors."""
14+
def __init__(self, message: str, nhs_numbers: list = None, exception=None):
15+
self.message = message
16+
self.nhs_numbers = nhs_numbers
17+
self.exception = exception
18+
super().__init__(message)
19+
20+
1121
@logging_decorator(prefix="id_sync", stream_name=STREAM_NAME)
1222
def handler(event_data, _):
1323

@@ -17,25 +27,28 @@ def handler(event_data, _):
1727
if record_count > 0:
1828
logger.info("id_sync processing event with %d records", record_count)
1929
error_count = 0
20-
file_keys = []
30+
nhs_numbers = []
2131
for record in event.records:
2232
record_result = process_record(record, None)
23-
file_keys.append(record_result["file_key"])
33+
nhs_numbers.append(record_result["nhs_number"])
2434
if record_result["status"] == "error":
2535
error_count += 1
2636
if error_count > 0:
27-
logger.error("id_sync processed %d records with %d errors", record_count, error_count)
28-
return {"status": "error", "message": f"Processed {record_count} records with {error_count} errors",
29-
"file_keys": file_keys}
37+
raise IdSyncException(message=f"Processed {record_count} records with {error_count} errors",
38+
nhs_numbers=nhs_numbers)
39+
3040
else:
31-
logger.info("id_sync successfully processed all %d records", record_count)
32-
return {"status": "success", "message": f"Successfully processed {record_count} records",
33-
"file_keys": file_keys}
41+
msg = f"Successfully processed {record_count} records"
42+
logger.info(msg)
43+
return {"status": "success", "message": msg, "nhs_numbers": nhs_numbers}
3444
else:
3545
logger.info("No records found in event")
3646
return {"status": "success", "message": "No records found in event"}
3747

38-
except Exception:
48+
except IdSyncException as e:
49+
logger.exception(f"id_sync error: {e.message}")
50+
raise e
51+
except Exception as e:
3952
msg = "Error processing id_sync event"
4053
logger.exception(msg)
41-
return {"status": "error", "message": msg}
54+
raise IdSyncException(message=msg, exception=e)

lambdas/id_sync/src/record_processor.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,17 @@ def process_nhs_number(nhs_number: str) -> Optional[str]:
2626

2727
patient_details_id = patient_details.get("id")
2828

29+
base_log_data = {"nhs_number": nhs_number}
2930
if patient_details_id:
3031
# if patient NHS != id, update patient index of vax events to new number
3132
if patient_details_id != nhs_number and patient_details_id:
3233
if ieds_check_exist(patient_details_id):
33-
return ieds_update_patient_id(patient_details_id, nhs_number)
34+
response = ieds_update_patient_id(patient_details_id, nhs_number)
3435
else:
35-
return {"status": "error", "message": f"No records returned for ID: {nhs_number}"}
36+
response = {"status": "error", "message": f"No records returned for ID: {nhs_number}"}
3637
else:
3738
return {"status": "success", "message": "No update required"}
3839
else:
39-
return {"status": "error", "message": f"No patient ID found for NHS number: {nhs_number}"}
40+
response = {"status": "error", "message": f"No patient ID found for NHS number: {nhs_number}"}
41+
response.update(base_log_data)
42+
return response

lambdas/id_sync/src/to_do_code.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
'''
22
record Processor
33
'''
4-
# from common.clients import get_delta_table
54
from boto3.dynamodb.conditions import Key
65
from os_vars import get_ieds_table_name, get_delta_table_name
7-
from common.clients import get_delta_table
86

97
ieds_tablename = get_ieds_table_name()
108
delta_tablename = get_delta_table_name()

0 commit comments

Comments
 (0)