I can run simple workflow
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Any, Generator
|
||||
|
||||
from core.Expando import Expando
|
||||
from utils.Datahelper import DataHelper
|
||||
|
||||
|
||||
class DataProcessor(ABC):
|
||||
"""Base class for all data processing components."""
|
||||
@@ -47,6 +50,45 @@ class DataPresenter(DataProcessor):
|
||||
yield self.present(data)
|
||||
|
||||
|
||||
class TableDataProducer(DataProducer):
|
||||
"""Base class for data producers that emit data from a repository."""
|
||||
|
||||
def __init__(self, session, settings_manager, repository_name, table_name):
|
||||
self._session = session
|
||||
self.settings_manager = settings_manager
|
||||
self.repository_name = repository_name
|
||||
self.table_name = table_name
|
||||
|
||||
def emit(self, data: Any = None) -> Generator[Any, None, None]:
|
||||
yield from DataHelper.get(self._session, self.settings_manager, self.repository_name, self.table_name, Expando)
|
||||
|
||||
|
||||
class DefaultDataPresenter(DataPresenter):
|
||||
"""Default data presenter that returns the input data unchanged."""
|
||||
|
||||
def __init__(self, columns_as_str: str):
|
||||
super().__init__()
|
||||
if not columns_as_str or columns_as_str == "*":
|
||||
self.mappings = None
|
||||
|
||||
else:
|
||||
|
||||
self.mappings = {}
|
||||
temp_mappings = [col.strip() for col in columns_as_str.split(",")]
|
||||
for mapping in temp_mappings:
|
||||
if "=" in mapping:
|
||||
key, value = mapping.split("=")
|
||||
self.mappings[key] = value
|
||||
else:
|
||||
self.mappings[mapping] = mapping
|
||||
|
||||
def present(self, data: Any) -> Any:
|
||||
if self.mappings is None:
|
||||
return data
|
||||
|
||||
return Expando(data.to_dict(self.mappings))
|
||||
|
||||
|
||||
class WorkflowEngine:
|
||||
"""Orchestrates the data processing pipeline using generators."""
|
||||
|
||||
@@ -93,4 +135,3 @@ class WorkflowEngine:
|
||||
Use this method when you need all results at once.
|
||||
"""
|
||||
return list(self.run())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user