SIENTIAPDE-1312
Refactor OPC handling by removing pod_id from initialization and updating logging format - Removed pod_id parameter from OPC class and repository initialization to streamline connection management. - Updated logging statements for improved readability during disconnection attempts and error handling.
This commit is contained in:
@@ -45,14 +45,13 @@ class OpcRepository(BaseActivity):
|
||||
self,
|
||||
opc_id: str,
|
||||
url: str,
|
||||
pod_id: str,
|
||||
logger: Logger,
|
||||
notification_handler: NotificationHandler,
|
||||
reconnection_interval: int = 60,
|
||||
server_uri: str | None = None,
|
||||
cert_path: str | None = None,
|
||||
private_key_path: str | None = None,
|
||||
server_cert_path: str | None = None
|
||||
server_cert_path: str | None = None,
|
||||
):
|
||||
self.url = url
|
||||
self.id = opc_id
|
||||
@@ -66,7 +65,6 @@ class OpcRepository(BaseActivity):
|
||||
self.last_reconnection_time: None | datetime = None
|
||||
self.notification_handler = notification_handler
|
||||
self.client: None | Client = None
|
||||
self.pod_id = pod_id
|
||||
|
||||
BaseActivity.__init__(self, logger, notification_handler, set_error_counter=True)
|
||||
|
||||
@@ -192,16 +190,20 @@ class OpcRepository(BaseActivity):
|
||||
error_stack = []
|
||||
for i in range(5):
|
||||
try:
|
||||
self.logger.info(f'Disconnecting from OPC UA server, attempt {i+1} of 5')
|
||||
self.logger.info(f'Disconnecting from OPC UA server, attempt {i + 1} of 5')
|
||||
await self.client.disconnect()
|
||||
return []
|
||||
except Exception as e:
|
||||
self.logger.error(f'Failed to disconnect from OPC UA server in attempt {i+1} of 5: {e}')
|
||||
error_stack.append({
|
||||
'attempt': i+1,
|
||||
'error': str(e),
|
||||
'traceback': traceback.format_exc(),
|
||||
})
|
||||
self.logger.error(
|
||||
f'Failed to disconnect from OPC UA server in attempt {i + 1} of 5: {e}'
|
||||
)
|
||||
error_stack.append(
|
||||
{
|
||||
'attempt': i + 1,
|
||||
'error': str(e),
|
||||
'traceback': traceback.format_exc(),
|
||||
}
|
||||
)
|
||||
await asyncio.sleep(0.1 * i)
|
||||
return error_stack
|
||||
|
||||
@@ -221,13 +223,13 @@ class OpcRepository(BaseActivity):
|
||||
self.send_notification(
|
||||
metadata=self.metadata,
|
||||
notification_id=f'OPC_DISCONNECTION_ERROR_{self.id}',
|
||||
message=f'Failed to disconnect from OPC server in 5 attempts: {errors}',
|
||||
message='Failed to disconnect from OPC server in 5 attempts.',
|
||||
block='opc_repository',
|
||||
level=NotificationLevel.ERROR,
|
||||
attachment_content=json.dumps(errors, indent=4),
|
||||
)
|
||||
else:
|
||||
self.logger.warning(f'Disconnected from OPC server {self.id} successfully')
|
||||
self.logger.warning(f'Disconnected from OPC server {self.id} successfully')
|
||||
|
||||
self.client = None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user