Skip to content

Commit

Permalink
Merge pull request #156 from salute-developers/fix/callback_id
Browse files Browse the repository at this point in the history
some changes for callback_id
  • Loading branch information
SyrexMinus authored Nov 20, 2023
2 parents a7478f2 + 1132b78 commit 3c92e0e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
13 changes: 5 additions & 8 deletions core/message/from_message.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# coding=utf-8
from typing import Iterable, Dict, Optional, Any, List, Union, Sequence, Tuple
from functools import cached_property
from typing import Iterable, Dict, Optional, Set, Any, List, Union, Tuple, Sequence
import json
import uuid

Expand Down Expand Up @@ -59,7 +60,7 @@ class SmartAppFromMessage:
def __init__(self, value: Dict[str, Any], topic_key: Optional[str] = None, creation_time: Optional[int] = None,
kafka_key: Optional[str] = None, headers: Optional[Sequence[Tuple[str, bytes]]] = 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
Expand All @@ -69,7 +70,7 @@ def __init__(self, value: Dict[str, Any], topic_key: Optional[str] = None, creat
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

Expand Down Expand Up @@ -223,7 +224,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
Expand All @@ -238,10 +239,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
Expand Down
4 changes: 2 additions & 2 deletions smart_kit/start_points/main_loop_kafka.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,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: ConsumerRecord, kafka_key):
Expand Down

0 comments on commit 3c92e0e

Please sign in to comment.