SIENTIAPDE-1205

Revert image tag in values.yaml to 0.4.4 and rename shutdown method in OpcRepository class

- Changed image tag in values.yaml from 0.4.5 back to 0.4.4.
- Renamed __del__ method to shutdown in OpcRepository for clarity.
- Enhanced connection validation logic in OpcRepository to improve error handling and logging.
This commit is contained in:
vitor-aignosi
2025-08-27 14:28:52 -03:00
parent 390e439a18
commit df2c64a1fa
2 changed files with 29 additions and 20 deletions

View File

@@ -158,7 +158,7 @@ class OpcRepository():
f"Failed to disconnect from OPC server: {e}", self.metadata) f"Failed to disconnect from OPC server: {e}", self.metadata)
self.client = None self.client = None
def __del__(self): def shutdown(self):
""" """
Disconnects from the OPC server when the object is destroyed. Disconnects from the OPC server when the object is destroyed.
""" """
@@ -170,7 +170,8 @@ class OpcRepository():
async def validate_connection(self) -> tuple[bool, dict[str, Any]]: async def validate_connection(self) -> tuple[bool, dict[str, Any]]:
""" """
Validates the connection to the OPC server. Validates the connection to the OPC server using protocol state checking.
If the connection is not established, it attempts to reconnect. If the connection is not established, it attempts to reconnect.
If the connection is established but the client is not connected, If the connection is established but the client is not connected,
it attempts to reconnect. it attempts to reconnect.
@@ -198,12 +199,10 @@ class OpcRepository():
# Check if client is connected using asyncua's connection state # Check if client is connected using asyncua's connection state
try: try:
# Try to get a simple node to test connection if self.client.uaclient.protocol is None or self.client.uaclient.protocol.state == "closed":
await self.client.get_node("ns=0;i=2253") # Server node # OPC server is not connected
except Exception:
self.logger.custom_error( self.logger.custom_error(
f"OPC server {self.id} is not connected", self.metadata) f"OPC server {self.id} is not connected", self.metadata)
if self.last_reconnection_time is None or (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:
await self.disconnect() await self.disconnect()
@@ -217,8 +216,18 @@ class OpcRepository():
"block": "opc_repository", "block": "opc_repository",
"level": NotificationLevel.WARNING "level": NotificationLevel.WARNING
} }
return True, {} return True, {}
except Exception as e:
trace = traceback.format_exc()
message = f"Failed to validate connection to OPC server: {e}"
self.logger.custom_error(message, self.metadata)
return False, {
"notification_id": f"OPC_CONNECTION_CHECK_ERROR_{self.id}",
"message": message,
"block": "opc_repository",
"level": NotificationLevel.ERROR,
"attachment_content": trace
}
async def write_data(self, node: str, value: Any, data_type: str, async def write_data(self, node: str, value: Any, data_type: str,
logger: Logger, metadata: dict[str, Any]) -> tuple[bool, dict[str, Any]]: logger: Logger, metadata: dict[str, Any]) -> tuple[bool, dict[str, Any]]:

View File

@@ -11,7 +11,7 @@ image:
# This sets the pull policy for images. # This sets the pull policy for images.
pullPolicy: Always pullPolicy: Always
# Overrides the image tag whose default is the chart appVersion. # Overrides the image tag whose default is the chart appVersion.
tag: "0.4.5" tag: "0.4.4"
# This is for the secrets for pulling an image from a private repository more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ # This is for the secrets for pulling an image from a private repository more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
imagePullSecrets: imagePullSecrets: