1
0
mirror of https://github.com/thingsboard/thingsboard-gateway synced 2025-10-26 22:31:42 +08:00

Added forced stop for OPCUA connector, made manager optional and fix for not saving tb_gateway json on connector configuration update

This commit is contained in:
imbeacon 2024-06-18 09:39:26 +03:00
parent b108d9b679
commit 893fa707f5
3 changed files with 32 additions and 22 deletions

View File

@ -97,8 +97,12 @@ class OpcUaConnector(Connector, Thread):
def close(self):
task = self.__loop.create_task(self.__reset_nodes())
start_time = monotonic()
while not task.done():
if monotonic() - start_time > 10:
self.__log.error('Failed to stop connector in 10 seconds, stopping it forcefully')
self.__loop.stop()
break
sleep(.2)
self.__stopped = True

View File

@ -292,26 +292,26 @@ class TBGatewayService:
self.__init_remote_configuration()
if path.exists('/tmp/gateway'):
try:
# deleting old manager if it was closed incorrectly
system('rm -rf /tmp/gateway')
except OSError as e:
log.exception(e)
if self.__config['thingsboard'].get('managerEnabled', False):
if path.exists('/tmp/gateway'):
try:
# deleting old manager if it was closed incorrectly
system('rm -rf /tmp/gateway')
except OSError as e:
log.exception(e)
manager_address = '/tmp/gateway'
if platform_system() == 'Windows':
manager_address = ('127.0.0.1', 9999)
self.manager = GatewayManager(address=manager_address, authkey=b'gateway')
manager_address = '/tmp/gateway'
if platform_system() == 'Windows':
manager_address = ('127.0.0.1', 9999)
self.manager = GatewayManager(address=manager_address, authkey=b'gateway')
if current_thread() is main_thread():
GatewayManager.register('get_gateway',
self.get_gateway,
proxytype=AutoProxy,
exposed=self.EXPOSED_GETTERS,
create_method=False)
self.server = self.manager.get_server()
self.server.serve_forever()
if current_thread() is main_thread():
GatewayManager.register('get_gateway',
self.get_gateway,
proxytype=AutoProxy,
exposed=self.EXPOSED_GETTERS,
create_method=False)
self.server = self.manager.get_server()
self.server.serve_forever()
def __init_variables(self):
self.stopped = False

View File

@ -214,7 +214,7 @@ class RemoteConfigurator:
continue
request_config = config[attr_name]
if not self._is_modified(attr_name, request_config):
if not self._is_modified(attr_name, request_config) and self.__is_running(request_config):
continue
request_processed = False
@ -583,8 +583,10 @@ class RemoteConfigurator:
self._gateway.available_connectors_by_id[connector_id])
self._gateway.tb_client.client.send_attributes({config['name']: config})
with open(self._gateway.get_config_path() + 'tb_gateway.json', 'w') as file:
file.writelines(dumps(self._get_general_config_in_local_format(), indent=' '))
except Exception as e:
LOG.exception(e)
LOG.exception("Exception on connector configuration update occurred:", exc_info=e)
def _handle_remote_logging_level_update(self, config):
self._gateway.tb_client.client.send_attributes({'RemoteLoggingLevel': config})
@ -761,3 +763,7 @@ class RemoteConfigurator:
for logger in config['loggers']:
if handler in config['loggers'][logger]['handlers']:
config['loggers'][logger]['handlers'].remove(handler)
def __is_running(self, request_config):
return (request_config.get('configurationJson', {}).get('id') in self._gateway.available_connectors_by_id or
request_config.get('name') in self._gateway.available_connectors_by_name)