From e75abde7015db4775525d21ae947d7a20e252c94 Mon Sep 17 00:00:00 2001 From: zbeacon Date: Thu, 30 Sep 2021 12:27:56 +0300 Subject: [PATCH] Fix for checking size of outgoing message --- thingsboard_gateway/gateway/tb_gateway_service.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/thingsboard_gateway/gateway/tb_gateway_service.py b/thingsboard_gateway/gateway/tb_gateway_service.py index 4bdfeaf49..22a0903e0 100644 --- a/thingsboard_gateway/gateway/tb_gateway_service.py +++ b/thingsboard_gateway/gateway/tb_gateway_service.py @@ -29,6 +29,7 @@ from thingsboard_gateway.gateway.tb_client import TBClient from thingsboard_gateway.storage.file.file_event_storage import FileEventStorage from thingsboard_gateway.storage.memory.memory_event_storage import MemoryEventStorage +from thingsboard_gateway.storage.sqlite.sqlite_event_storage import SQLiteEventStorage from thingsboard_gateway.tb_utility.tb_gateway_remote_configurator import RemoteConfigurator from thingsboard_gateway.tb_utility.tb_loader import TBModuleLoader from thingsboard_gateway.tb_utility.tb_logger import TBLoggerHandler @@ -36,7 +37,6 @@ from thingsboard_gateway.tb_utility.tb_updater import TBUpdater from thingsboard_gateway.tb_utility.tb_utility import TBUtility -from thingsboard_gateway.storage.sqlite.sqlite_event_storage import SQLiteEventStorage log = logging.getLogger('service') main_handler = logging.handlers.MemoryHandler(-1) @@ -428,7 +428,7 @@ def __read_data_from_storage(self): while not self.stopped: try: if self.tb_client.is_connected(): - size = getsizeof(devices_data_in_event_pack) + size = getsizeof(str(devices_data_in_event_pack))-2 events = [] if self.__remote_configurator is None or not self.__remote_configurator.in_process: @@ -450,24 +450,24 @@ def __read_data_from_storage(self): if current_event.get("telemetry"): if isinstance(current_event["telemetry"], list): for item in current_event["telemetry"]: - size += getsizeof(item) + size += getsizeof(str(item))-2 size = self.check_size(size, devices_data_in_event_pack) devices_data_in_event_pack[current_event["deviceName"]]["telemetry"].append( item) else: - size += getsizeof(current_event["telemetry"]) + size += getsizeof(str(current_event["telemetry"]))-2 size = self.check_size(size, devices_data_in_event_pack) devices_data_in_event_pack[current_event["deviceName"]]["telemetry"].append( current_event["telemetry"]) if current_event.get("attributes"): if isinstance(current_event["attributes"], list): for item in current_event["attributes"]: - size += getsizeof(item) + size += getsizeof(str(item))-2 size = self.check_size(size, devices_data_in_event_pack) devices_data_in_event_pack[current_event["deviceName"]]["attributes"].update( item.items()) else: - size += getsizeof(current_event["attributes"].items()) + size += getsizeof(str(current_event["attributes"].items()))-2 size = self.check_size(size, devices_data_in_event_pack) devices_data_in_event_pack[current_event["deviceName"]]["attributes"].update( current_event["attributes"].items())