Skip to content

Commit

Permalink
Filter out non-courtdoc messages from eventbus
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyhashemi committed Oct 9, 2023
1 parent c27376b commit 83eddc7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
17 changes: 17 additions & 0 deletions ds-caselaw-ingester/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ def save_s3_response(self, sqs_client, s3_client):

return filename

def validate(self):
return


class V2Message(Message):
def is_v1(self):
Expand All @@ -120,13 +123,25 @@ def save_s3_response(self, sqs_client, s3_client):
print(f"tar.gz saved locally as {filename}")
return filename

def validate(self):
message_type = self.message["properties"]["messageType"]
if (
message_type
!= "uk.gov.nationalarchives.da.messages.request.courtdocument.parse.RequestCourtDocumentParse"
):
raise WrongMessageTypeError(f"Received message with type: {message_type}")


class ReportableException(Exception):
def __init__(self, *args, **kwargs):
rollbar.report_message("Something happened!", "warning", str(self))
super().__init__(*args, **kwargs)


class WrongMessageTypeError(ReportableException):
pass


class S3HTTPError(ReportableException):
pass

Expand Down Expand Up @@ -413,6 +428,8 @@ def unpublish_updated_judgment(uri):
def handler(event, context):
message = Message.from_event(event)

message.validate()

consignment_reference = message.get_consignment_reference()
print(f"Ingester Start: Consignment reference {consignment_reference}")
print(f"Received Message: {message.message}")
Expand Down
3 changes: 1 addition & 2 deletions ds-caselaw-ingester/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
v2_message_raw = """
{
"properties": {
"messageType":
"uk.gov.nationalarchives.tre.messages.judgmentpackage.available.JudgmentPackageAvailable",
"messageType": "uk.gov.nationalarchives.da.messages.request.courtdocument.parse.RequestCourtDocumentParse",
"timestamp": "2023-05-15T09:14:53.791409Z",
"function": "staging-tre-judgment-packer-lambda",
"producer": "TRE",
Expand Down

0 comments on commit 83eddc7

Please sign in to comment.