SIENTIAPDE-1445
Update GITHUB_BRANCH to feature/SIENTIAPDE-1445 and enhance formatters with a new registry for workflow types, improving configuration management. Refactor process_schedules to utilize the new registry and add error handling for unsupported workflow types. Update tests to validate new functionality and ensure proper integration.
This commit is contained in:
@@ -2,10 +2,10 @@ from temporalio import activity, workflow
|
||||
|
||||
with workflow.unsafe.imports_passed_through():
|
||||
import json
|
||||
from collections.abc import Hashable
|
||||
from collections.abc import Callable, Hashable
|
||||
from logging import Logger
|
||||
from math import ceil
|
||||
from typing import Any
|
||||
from typing import Any, TypedDict
|
||||
|
||||
from pandas import DataFrame
|
||||
from sientia_do.notifications.handlers import CoreNotificationHandler as NotificationHandler
|
||||
@@ -18,6 +18,7 @@ with workflow.unsafe.imports_passed_through():
|
||||
drift,
|
||||
gather_read_tags,
|
||||
minimal_retrain,
|
||||
pi_web_api_scouter,
|
||||
predictions_batch,
|
||||
scouter,
|
||||
simple_metrics,
|
||||
@@ -26,6 +27,68 @@ with workflow.unsafe.imports_passed_through():
|
||||
topic_separator = '\n ========== \n'
|
||||
|
||||
|
||||
class ScheduleType(TypedDict):
|
||||
"""
|
||||
Type definition for schedule type configuration entries.
|
||||
|
||||
Each schedule type entry maps a workflow type string to its corresponding
|
||||
namespace and configuration builder function.
|
||||
|
||||
Attributes:
|
||||
namespace (str): The Temporal namespace where workflows of this type execute.
|
||||
Valid values: 'scouter', 'laborious'
|
||||
function (Callable): Configuration builder function that transforms pipeline
|
||||
configuration into Temporal-compatible workflow arguments
|
||||
"""
|
||||
|
||||
namespace: str
|
||||
function: Callable
|
||||
|
||||
|
||||
schedule_types: dict[str, ScheduleType] = {
|
||||
'scouter': {
|
||||
'namespace': 'scouter',
|
||||
'function': scouter,
|
||||
},
|
||||
'pi_web_api_scouter': {
|
||||
'namespace': 'scouter',
|
||||
'function': pi_web_api_scouter,
|
||||
},
|
||||
'predictions_batch': {
|
||||
'namespace': 'laborious',
|
||||
'function': predictions_batch,
|
||||
},
|
||||
'minimal_retrain': {
|
||||
'namespace': 'laborious',
|
||||
'function': minimal_retrain,
|
||||
},
|
||||
'drift': {
|
||||
'namespace': 'laborious',
|
||||
'function': drift,
|
||||
},
|
||||
'simple_metrics': {
|
||||
'namespace': 'laborious',
|
||||
'function': simple_metrics,
|
||||
},
|
||||
}
|
||||
"""
|
||||
Registry mapping workflow types to their namespace and configuration builder functions.
|
||||
|
||||
Supported workflow types:
|
||||
- scouter: OPC data collection using OPC UA protocol
|
||||
- pi_web_api_scouter: Data collection using PI Web API
|
||||
- predictions_batch: ML model prediction workflows with OPC write-back
|
||||
- minimal_retrain: Model retraining workflows using SQL queries
|
||||
- drift: Data drift detection and monitoring workflows
|
||||
- simple_metrics: Model performance metrics computation workflows
|
||||
|
||||
Each entry specifies:
|
||||
- namespace: Target Temporal namespace for workflow execution
|
||||
- function: Configuration builder that transforms MongoDB pipeline config
|
||||
into Temporal workflow arguments
|
||||
"""
|
||||
|
||||
|
||||
class Formatters(SientiaMonitoring):
|
||||
"""
|
||||
Schedule and slot configuration formatting and notification filtering activity.
|
||||
@@ -115,41 +178,22 @@ class Formatters(SientiaMonitoring):
|
||||
}
|
||||
|
||||
for pipeline in pipelines:
|
||||
if pipeline['workflow_type'] == 'scouter':
|
||||
schedule_config[self.scouter_namespace][pipeline['schedule_name']] = {
|
||||
**scouter(pipeline),
|
||||
'updated_at': pipeline.get(
|
||||
'updated_at', now().strftime(DATETIME_FORMAT_MS_WITH_TZ)
|
||||
),
|
||||
}
|
||||
elif pipeline['workflow_type'] == 'predictions_batch':
|
||||
schedule_config[self.laborious_namespace][pipeline['schedule_name']] = {
|
||||
**predictions_batch(pipeline),
|
||||
'updated_at': pipeline.get(
|
||||
'updated_at', now().strftime(DATETIME_FORMAT_MS_WITH_TZ)
|
||||
),
|
||||
}
|
||||
elif pipeline['workflow_type'] == 'minimal_retrain':
|
||||
schedule_config[self.laborious_namespace][pipeline['schedule_name']] = {
|
||||
**minimal_retrain(pipeline),
|
||||
'updated_at': pipeline.get(
|
||||
'updated_at', now().strftime(DATETIME_FORMAT_MS_WITH_TZ)
|
||||
),
|
||||
}
|
||||
elif pipeline['workflow_type'] == 'drift':
|
||||
schedule_config[self.laborious_namespace][pipeline['schedule_name']] = {
|
||||
**drift(pipeline),
|
||||
'updated_at': pipeline.get(
|
||||
'updated_at', now().strftime(DATETIME_FORMAT_MS_WITH_TZ)
|
||||
),
|
||||
}
|
||||
elif pipeline['workflow_type'] == 'simple_metrics':
|
||||
schedule_config[self.laborious_namespace][pipeline['schedule_name']] = {
|
||||
**simple_metrics(pipeline),
|
||||
'updated_at': pipeline.get(
|
||||
'updated_at', now().strftime(DATETIME_FORMAT_MS_WITH_TZ)
|
||||
),
|
||||
}
|
||||
workflow_type = pipeline['workflow_type']
|
||||
|
||||
if workflow_type not in schedule_types:
|
||||
self.error(f'Workflow type {workflow_type} not supported', metadata=metadata)
|
||||
continue
|
||||
|
||||
schedule_type = schedule_types[workflow_type]
|
||||
namespace = schedule_type['namespace']
|
||||
function = schedule_type['function']
|
||||
|
||||
schedule_config[namespace][pipeline['schedule_name']] = {
|
||||
**function(pipeline),
|
||||
'updated_at': pipeline.get(
|
||||
'updated_at', now().strftime(DATETIME_FORMAT_MS_WITH_TZ)
|
||||
),
|
||||
}
|
||||
|
||||
self.info('Processed schedules', metadata=metadata)
|
||||
self.debug(json.dumps(schedule_config, indent=4, sort_keys=True), metadata=metadata)
|
||||
|
||||
Reference in New Issue
Block a user