SIENTIAPDE-1231
Enhance validation script and refactor code in various modules - Updated the validation script to include automatic code formatting and linting fixes using Ruff. - Removed the `clean_tmp_files` method from the Gates class to streamline functionality. - Simplified conditional checks in the OpcRepository for better clarity and error handling. - Added model ID to the minimal retrain workflow for improved tracking. - Introduced new test cases for error handling in MLFlow and storage operations, ensuring robustness in repository interactions.
This commit is contained in:
@@ -3,8 +3,6 @@ from temporalio import activity, workflow
|
||||
with workflow.unsafe.imports_passed_through():
|
||||
import traceback
|
||||
from collections.abc import Callable, Mapping
|
||||
from os import path
|
||||
from shutil import rmtree
|
||||
from typing import Any
|
||||
|
||||
from pandas import DataFrame
|
||||
@@ -628,19 +626,3 @@ class Gates(BaseActivity):
|
||||
).observe(response_time)
|
||||
|
||||
self.info(f'Metrics written for model {metadata["model_name"]}', metadata)
|
||||
|
||||
@activity.defn(name='clean_tmp_files')
|
||||
async def clean_tmp_files(self, input_data: dict[str, Any]):
|
||||
"""
|
||||
Clean temporary files in the tmp directory.
|
||||
"""
|
||||
model_name = input_data['model_name']
|
||||
metadata = input_data['metadata']
|
||||
self.info(f'Cleaning tmp files for model {model_name}...', metadata)
|
||||
|
||||
if path.exists(f'tmp/retrain_data/{model_name}'):
|
||||
rmtree(f'tmp/retrain_data/{model_name}')
|
||||
if path.exists(f'tmp/artifacts/{model_name}'):
|
||||
rmtree(f'tmp/artifacts/{model_name}')
|
||||
|
||||
self.info('Tmp files cleaned', metadata)
|
||||
|
||||
@@ -304,7 +304,7 @@ class MLFlowRepository:
|
||||
if model_type == 'predict':
|
||||
model = self.load_predict_model(model_name, flavor)
|
||||
|
||||
elif model_type == 'transform':
|
||||
else:
|
||||
model = self.load_transform_model(model_name, flavor)
|
||||
|
||||
return model, artifact_path
|
||||
|
||||
@@ -92,14 +92,11 @@ class OpcRepository:
|
||||
- Session Timeout: 10,000,000 ms
|
||||
"""
|
||||
|
||||
if not all([self.cert_path, self.private_key_path]):
|
||||
if self.cert_path is None or self.private_key_path is None:
|
||||
raise ValueError(
|
||||
'Certificate and private key paths must be provided for secure connection.'
|
||||
)
|
||||
|
||||
if self.cert_path is None or self.private_key_path is None:
|
||||
raise ValueError('Certificate and private key paths cannot be None')
|
||||
|
||||
cert = Path(self.cert_path)
|
||||
private_key = Path(self.private_key_path)
|
||||
server_cert = Path(self.server_cert_path) if self.server_cert_path else None
|
||||
@@ -316,14 +313,8 @@ class OpcRepository:
|
||||
start_time = time.time()
|
||||
|
||||
try:
|
||||
if self.client is None:
|
||||
return False, {
|
||||
'notification_id': f'OPC_WRITE_GET_NODE_ERROR_{self.id}',
|
||||
'message': 'Client is not initialized',
|
||||
'block': 'opc_repository',
|
||||
'level': NotificationLevel.ERROR,
|
||||
}
|
||||
node_obj = self.client.get_node(node)
|
||||
# ignored because self.validate_connection is called before, so we know self.client is not None
|
||||
node_obj = self.client.get_node(node) # type: ignore[union-attr]
|
||||
except Exception as e:
|
||||
trace = traceback.format_exc()
|
||||
logger.custom_error(trace, metadata.get('schedule_name', 'N/A'))
|
||||
|
||||
@@ -116,6 +116,7 @@ class MinimalRetrain:
|
||||
**metadata,
|
||||
'experiment_response': experiment_response,
|
||||
'model_name': model_name,
|
||||
'model_id': input_data['model_id'],
|
||||
'update_report': update_report,
|
||||
},
|
||||
retry_policy=retry_policy,
|
||||
|
||||
Reference in New Issue
Block a user