From 232bb3586e2dc857cc86377ca642dccc1e3956e7 Mon Sep 17 00:00:00 2001 From: cortadocodes Date: Tue, 21 Nov 2023 18:06:09 +0000 Subject: [PATCH] REF: Rename functions to use "event" instead of "message" --- octue/cloud/pub_sub/message_handler.py | 6 ++-- octue/cloud/pub_sub/service.py | 6 ++-- octue/cloud/validation.py | 40 +++++++++++++------------- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/octue/cloud/pub_sub/message_handler.py b/octue/cloud/pub_sub/message_handler.py index f7aa839fb..9bf38c22b 100644 --- a/octue/cloud/pub_sub/message_handler.py +++ b/octue/cloud/pub_sub/message_handler.py @@ -12,7 +12,7 @@ from octue.cloud import EXCEPTIONS_MAPPING from octue.cloud.pub_sub.messages import extract_event_and_attributes_from_pub_sub -from octue.cloud.validation import SERVICE_COMMUNICATION_SCHEMA, is_message_valid +from octue.cloud.validation import SERVICE_COMMUNICATION_SCHEMA, is_event_valid from octue.definitions import GOOGLE_COMPUTE_PROVIDERS from octue.log_handlers import COLOUR_PALETTE from octue.resources.manifest import Manifest @@ -232,8 +232,8 @@ def _pull_and_enqueue_message(self, timeout): if not self._child_sdk_version: self._child_sdk_version = attributes["octue_sdk_version"] - if not is_message_valid( - message=event, + if not is_event_valid( + event=event, attributes=attributes, receiving_service=self.receiving_service, parent_sdk_version=importlib.metadata.version("octue"), diff --git a/octue/cloud/pub_sub/service.py b/octue/cloud/pub_sub/service.py index bb3ce937c..677a13748 100644 --- a/octue/cloud/pub_sub/service.py +++ b/octue/cloud/pub_sub/service.py @@ -26,7 +26,7 @@ split_service_id, validate_sruid, ) -from octue.cloud.validation import raise_if_message_is_invalid +from octue.cloud.validation import raise_if_event_is_invalid from octue.compatibility import warn_if_incompatible from octue.utils.decoders import OctueJSONDecoder from octue.utils.encoders import OctueJSONEncoder @@ -546,8 +546,8 @@ def _parse_question(self, question): if event.get("input_manifest"): event_for_validation["input_manifest"] = json.loads(event["input_manifest"], cls=OctueJSONDecoder) - raise_if_message_is_invalid( - message=event_for_validation, + raise_if_event_is_invalid( + event=event_for_validation, attributes=attributes, receiving_service=self, parent_sdk_version=attributes["octue_sdk_version"], diff --git a/octue/cloud/validation.py b/octue/cloud/validation.py index 461c0ebb4..f0b510d0f 100644 --- a/octue/cloud/validation.py +++ b/octue/cloud/validation.py @@ -11,20 +11,20 @@ SERVICE_COMMUNICATION_SCHEMA_INFO_URL = "https://strands.octue.com/octue/service-communication" -def is_message_valid(message, attributes, receiving_service, parent_sdk_version, child_sdk_version, schema=None): - """Check if the message or its attributes are valid according to the schema. +def is_event_valid(event, attributes, receiving_service, parent_sdk_version, child_sdk_version, schema=None): + """Check if the event or its attributes are valid according to the schema. - :param dict message: the message to validate - :param dict attributes: the attributes of the message to validate - :param octue.cloud.pub_sub.service.Service receiving_service: the service that received the message and is validating it + :param dict event: the event to validate + :param dict attributes: the attributes of the event to validate + :param octue.cloud.pub_sub.service.Service receiving_service: the service that received the event and is validating it :param str parent_sdk_version: the semantic version of Octue SDK running the parent :param str child_sdk_version: the semantic version of Octue SDK running the child - :param dict|None schema: the schema to validate the message and its attributes against; if `None`, this defaults to the service communication schema used in this version of Octue SDK - :return bool: `True` if the message and its attributes are valid + :param dict|None schema: the schema to validate the event and its attributes against; if `None`, this defaults to the service communication schema used in this version of Octue SDK + :return bool: `True` if the event and its attributes are valid """ try: - raise_if_message_is_invalid( - message, + raise_if_event_is_invalid( + event, attributes, receiving_service, parent_sdk_version, @@ -37,38 +37,38 @@ def is_message_valid(message, attributes, receiving_service, parent_sdk_version, return True -def raise_if_message_is_invalid( - message, +def raise_if_event_is_invalid( + event, attributes, receiving_service, parent_sdk_version, child_sdk_version, schema=None, ): - """Raise an error if the message or its attributes aren't valid according to the schema. + """Raise an error if the event or its attributes aren't valid according to the schema. - :param dict message: the message to validate - :param dict attributes: the attributes of the message to validate - :param octue.cloud.pub_sub.service.Service receiving_service: the service that received the message and is validating it + :param dict event: the event to validate + :param dict attributes: the attributes of the event to validate + :param octue.cloud.pub_sub.service.Service receiving_service: the service that received the event and is validating it :param str parent_sdk_version: the semantic version of Octue SDK running the parent :param str child_sdk_version: the semantic version of Octue SDK running the child - :param dict|None schema: the schema to validate the message and its attributes against; if `None`, this defaults to the service communication schema used in this version of Octue SDK - :raise jsonschema.ValidationError: if the message or its attributes are invalid + :param dict|None schema: the schema to validate the event and its attributes against; if `None`, this defaults to the service communication schema used in this version of Octue SDK + :raise jsonschema.ValidationError: if the event or its attributes are invalid :return None: """ if schema is None: schema = {"$ref": SERVICE_COMMUNICATION_SCHEMA} try: - jsonschema.validate({"event": message, "attributes": dict(attributes)}, schema) + jsonschema.validate({"event": event, "attributes": dict(attributes)}, schema) except jsonschema.ValidationError as error: warn_if_incompatible(parent_sdk_version=parent_sdk_version, child_sdk_version=child_sdk_version) logger.exception( - "%r received a message that doesn't conform with the service communication schema (%s): %r.", + "%r received an event that doesn't conform with the service communication schema (%s): %r.", receiving_service, SERVICE_COMMUNICATION_SCHEMA_INFO_URL, - message, + event, ) raise error