SIENTIAPDE-1163

Refactor OPC connection handling to improve error notifications and update GITHUB_BRANCH in values.yaml for MongoDB integration. Change requirements.txt to point to local dataops library path.
This commit is contained in:
2025-07-17 11:02:41 -03:00
parent c17792020e
commit 694ad265c8
5 changed files with 74 additions and 50 deletions

View File

@@ -22,7 +22,7 @@ class OPC(BaseActivity):
self.notification_handler = notification_handler
self.opc_servers = opc_servers
self.opc_repository = {}
self.opc_repository: dict[str, OpcRepository] = {}
for id, server in opc_servers.items():
self.opc_repository[id] = OpcRepository(
id=server['id'],
@@ -35,8 +35,22 @@ class OPC(BaseActivity):
notification_handler=self.notification_handler,
reconnection_interval=server['reconnection_interval'],
)
self.opc_repository[id].connect()
is_connected, error_data = self.opc_repository[id].connect()
if not is_connected:
self.send_notification(
metadata={
'model_id': '-',
'model_name': '-',
'workflow_name': '-',
'schedule_name': 'INITIALIZATION'
},
notification_id=error_data['notification_id'],
message=error_data['message'],
block=error_data['block'],
level=error_data.get('level', NotificationLevel.ERROR),
attachment_content=error_data.get(
'attachment_content', None)
)
BaseActivity.__init__(self, logger, notification_handler)
def write_data(self, server_id: str, tag: str, data: Any,
@@ -56,8 +70,20 @@ class OPC(BaseActivity):
"""
try:
return self.opc_repository[server_id].write_data(
is_success, error_data = self.opc_repository[server_id].write_data(
tag, data, data_type, self.logger, metadata)
if not is_success:
self.send_notification(
metadata=metadata,
notification_id=error_data['notification_id'],
message=error_data['message'],
block=error_data['block'],
level=error_data.get('level', NotificationLevel.ERROR),
attachment_content=error_data.get(
'attachment_content', None)
)
return False
return True
except Exception as e:
trace = traceback.format_exc()
self.send_notification(