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 a1c9cbe
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ds-caselaw-ingester/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ def save_s3_response(self, sqs_client, s3_client):
out.close()

return filename

def validate(self):
return


class V2Message(Message):
Expand All @@ -119,13 +122,21 @@ def save_s3_response(self, sqs_client, s3_client):
raise RuntimeError(f"File {filename} not created")
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.tre.messages.courtdocumentpackage.available.CourtDocumentPackageAvailable":
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 +424,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

0 comments on commit a1c9cbe

Please sign in to comment.