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
|
tuple[str | None, int, str]: (policy, confidence, comments) based in priority
|
||||||
list and filter configuration and functions.
|
list and filter configuration and functions.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.debug(f"Input data: {input_data}")
|
|
||||||
|
|
||||||
metadata = input_data['metadata']
|
metadata = input_data['metadata']
|
||||||
|
|
||||||
self.debug("Performing input gate...", metadata)
|
self.debug("Performing input gate...", metadata)
|
||||||
|
|||||||
@@ -114,6 +114,7 @@ class OpcRepository():
|
|||||||
Returns:
|
Returns:
|
||||||
bool: True if the connection was successful, False otherwise.
|
bool: True if the connection was successful, False otherwise.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.last_reconnection_time = datetime.now()
|
self.last_reconnection_time = datetime.now()
|
||||||
self.client.connect()
|
self.client.connect()
|
||||||
@@ -136,9 +137,12 @@ class OpcRepository():
|
|||||||
"""
|
"""
|
||||||
if self.client is None:
|
if self.client is None:
|
||||||
return
|
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.client = None
|
||||||
self.logger.info('Disconnected from OPC server')
|
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
"""
|
"""
|
||||||
@@ -182,11 +186,12 @@ class OpcRepository():
|
|||||||
|
|
||||||
self.logger.error(
|
self.logger.error(
|
||||||
f"OPC server {self.id} is not connected")
|
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.reconnection_interval:
|
||||||
|
self.disconnect()
|
||||||
self.logger.error(
|
self.logger.error(
|
||||||
f"Trying to reconnect to OPC server {self.id}...")
|
f"Trying to reconnect to OPC server {self.id}...")
|
||||||
return self.try_connect()
|
return self.connect()
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user