SIENTIAPDE-1110
Refactor Gates and OpcRepository for improved logging and error handling. Removed debug statement in Gates and enhanced disconnect method in OpcRepository to log disconnection status and handle exceptions.
This commit is contained in:
@@ -64,9 +64,6 @@ class Gates(BaseActivity):
|
||||
tuple[str | None, int, str]: (policy, confidence, comments) based in priority
|
||||
list and filter configuration and functions.
|
||||
"""
|
||||
|
||||
self.debug(f"Input data: {input_data}")
|
||||
|
||||
metadata = input_data['metadata']
|
||||
|
||||
self.debug("Performing input gate...", metadata)
|
||||
|
||||
@@ -114,6 +114,7 @@ class OpcRepository():
|
||||
Returns:
|
||||
bool: True if the connection was successful, False otherwise.
|
||||
"""
|
||||
|
||||
try:
|
||||
self.last_reconnection_time = datetime.now()
|
||||
self.client.connect()
|
||||
@@ -136,9 +137,12 @@ class OpcRepository():
|
||||
"""
|
||||
if self.client is None:
|
||||
return
|
||||
self.client.disconnect()
|
||||
try:
|
||||
self.client.disconnect()
|
||||
self.logger.info('Disconnected from OPC server')
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to disconnect from OPC server: {e}")
|
||||
self.client = None
|
||||
self.logger.info('Disconnected from OPC server')
|
||||
|
||||
def __del__(self):
|
||||
"""
|
||||
@@ -182,11 +186,12 @@ class OpcRepository():
|
||||
|
||||
self.logger.error(
|
||||
f"OPC server {self.id} is not connected")
|
||||
if (datetime.now() - self.last_reconnection_time).total_seconds(
|
||||
if self.last_reconnection_time is None or (datetime.now() - self.last_reconnection_time).total_seconds(
|
||||
) > self.reconnection_interval:
|
||||
self.disconnect()
|
||||
self.logger.error(
|
||||
f"Trying to reconnect to OPC server {self.id}...")
|
||||
return self.try_connect()
|
||||
return self.connect()
|
||||
|
||||
return False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user