From 3fca7ddd7f35fc62326ee29091171cc08e382ec0 Mon Sep 17 00:00:00 2001 From: Danil D Date: Mon, 30 Oct 2023 11:41:12 +0300 Subject: [PATCH 1/2] some changes for callback_id --- core/message/from_message.py | 11 ++++------- smart_kit/start_points/main_loop_kafka.py | 4 ++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/core/message/from_message.py b/core/message/from_message.py index d92f254b..54b5e110 100644 --- a/core/message/from_message.py +++ b/core/message/from_message.py @@ -1,4 +1,5 @@ # coding=utf-8 +from functools import cached_property from typing import Iterable, Dict, Optional, Set, Any, List, Union, Tuple import json import uuid @@ -59,7 +60,7 @@ class SmartAppFromMessage: def __init__(self, value: Dict[str, Any], topic_key: str = None, creation_time: Optional[int] = None, kafka_key: Optional[str] = None, headers: Optional[Iterable[Tuple[Any, Any]]] = None, masking_fields: Optional[Union[Dict[str, int], List[str]]] = None, headers_required: bool = True, - validators: Iterable[MessageValidator] = ()): + validators: Iterable[MessageValidator] = (), callback_id: Optional[str] = None): self.logging_uuid = str(uuid.uuid4()) self._value = value self.topic_key = topic_key @@ -69,7 +70,7 @@ def __init__(self, value: Dict[str, Any], topic_key: str = None, creation_time: if self._headers_required and headers is None: raise LookupError(f"{self.__class__.__name__} no incoming headers.") self.headers = Headers(headers or {}) - self._callback_id = None # FIXME: by some reason it possibly to change callback_id + self._callback_id = callback_id # FIXME: by some reason it possibly to change callback_id self.masking_fields = masking_fields self.validators = validators @@ -219,7 +220,7 @@ def annotations(self) -> Dict[str, Dict[str, float]]: annotations[annotation] = dict(zip(classes, probas)) return annotations - @property + @cached_property def callback_id(self) -> Optional[str]: if self._callback_id is not None: return self._callback_id @@ -234,10 +235,6 @@ def callback_id(self) -> Optional[str]: params={log_const.KEY_NAME: "callback_id_missing", "message_id": self.incremental_id}, level="WARNING") return None - @callback_id.setter - def callback_id(self, value: str): - self._callback_id = value - @property def has_callback_id(self): return self._callback_id is not None or self.headers.get(self._callback_id_header_name) is not None diff --git a/smart_kit/start_points/main_loop_kafka.py b/smart_kit/start_points/main_loop_kafka.py index 6573d8d1..b150f532 100644 --- a/smart_kit/start_points/main_loop_kafka.py +++ b/smart_kit/start_points/main_loop_kafka.py @@ -353,8 +353,8 @@ def _generate_answers(self, user, commands, message, **kwargs): def _get_timeout_from_message(self, orig_message_raw: Dict, callback_id, headers): timeout_from_message = SmartAppFromMessage(orig_message_raw, headers=headers, masking_fields=self.masking_fields, - validators=self.from_msg_validators) - timeout_from_message.callback_id = callback_id + validators=self.from_msg_validators, + callback_id=callback_id) return timeout_from_message def _get_topic_key(self, mq_message: KafkaMessage, kafka_key): From 1132b78d78246543719cb6ad62516f449b4dc41e Mon Sep 17 00:00:00 2001 From: Danil D Date: Thu, 9 Nov 2023 11:32:00 +0300 Subject: [PATCH 2/2] some changes for callback_id --- core/message/from_message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/message/from_message.py b/core/message/from_message.py index 8b006425..f9e0bb3f 100644 --- a/core/message/from_message.py +++ b/core/message/from_message.py @@ -1,6 +1,6 @@ # coding=utf-8 from functools import cached_property -from typing import Iterable, Dict, Optional, Set, Any, List, Union, Tuple +from typing import Iterable, Dict, Optional, Set, Any, List, Union, Tuple, Sequence import json import uuid