Skip to content

Commit

Permalink
Filter out non-courtdoc messages from eventbus less aggressively
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyhashemi committed Oct 9, 2023
1 parent c27376b commit 4d6d5c9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion aws_examples/sns/parsed-judgment-v2.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"properties": {
"messageType": "uk.gov.nationalarchives.tre.messages.courtdocumentpackage.available.CourtDocumentPackageAvailable",
"messageType": "uk.gov.nationalarchives.da.messages.courtdocumentpackage.available.CourtDocumentPackageAvailable",
"timestamp": "2023-06-28T09:09:25.670688Z",
"function": "staging-tre-court-document-pack-lambda",
"producer": "TRE",
Expand Down
19 changes: 19 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 is_valid_ingester_message(self):
return True


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 is_valid_ingester_message(self):
message_type = self.message["properties"]["messageType"]
print(f"Message type: {message_type}")
return (
message_type
== "uk.gov.nationalarchives.da.messages.courtdocumentpackage.available.CourtDocumentPackageAvailable"
)


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,10 @@ def unpublish_updated_judgment(uri):
def handler(event, context):
message = Message.from_event(event)

if message.is_valid_ingester_message():
print("Message type is not valid for ingestion. Skipping.")
return

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

0 comments on commit 4d6d5c9

Please sign in to comment.