SIENTIAPDE-1163
Refactor Ingestor and Manager classes to use CoreNotificationHandler and improve metadata handling - Updated Ingestor class to initialize logger using get_logger and replaced notification handler initialization with metadata dictionary. - Refactored DataManager, IngestorManager, OpcManager, and ResourceManager classes to inherit from BaseActivity, allowing for consistent logger and notification handler usage. - Enhanced notification handling by integrating metadata into notification methods across various managers. - Added .vscode/ to .gitignore to exclude VSCode configuration files.
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
from logging import Formatter, StreamHandler, getLogger
|
||||
from os import getenv
|
||||
from copy import deepcopy
|
||||
from typing import Dict, Any
|
||||
@@ -62,8 +61,7 @@ class Ingestor:
|
||||
self.mongo_connection_string = f"mongodb://{mongo_username}:{mongo_password}@{mongo_url}"
|
||||
|
||||
self.kafka_servers = kafka_servers.split(",")
|
||||
self.logger = None
|
||||
self.init_logger()
|
||||
self.logger = get_logger(__name__)
|
||||
self.notification_handler = NotificationHandler(
|
||||
connection_string=self.mongo_connection_string,
|
||||
database=self.mongo_database,
|
||||
@@ -71,11 +69,12 @@ class Ingestor:
|
||||
project_name="OPC_INGESTOR"
|
||||
)
|
||||
|
||||
self.notification_handler.base_notification.pipeline = 'OPC_INGESTOR'
|
||||
self.notification_handler.base_notification.trigger = 'INGESTOR'
|
||||
self.notification_handler.base_notification.model_name = '-'
|
||||
self.notification_handler.base_notification.model_id = '-'
|
||||
|
||||
self.metadata = {
|
||||
'schedule_name': 'OPC_INGESTOR',
|
||||
'trigger': 'INGESTOR',
|
||||
'model_name': '-',
|
||||
'model_id': '-'
|
||||
}
|
||||
self.ingestor_manager = None
|
||||
|
||||
def shutdown(self):
|
||||
@@ -85,28 +84,6 @@ class Ingestor:
|
||||
def __del__(self):
|
||||
self.shutdown()
|
||||
|
||||
def init_logger(self):
|
||||
"""
|
||||
Initializes a logger instance for the class.
|
||||
This method sets up a logger with a specified log level, a stream handler,
|
||||
and a formatter. The log level is determined by the environment variable
|
||||
"LOG_LEVEL", defaulting to "INFO" if not set. The logger is then attached
|
||||
to the instance for use throughout the class.
|
||||
Attributes:
|
||||
self.logger (logging.Logger): The configured logger instance.
|
||||
"""
|
||||
|
||||
logger = getLogger(__name__)
|
||||
logger.setLevel(getenv("LOG_LEVEL", "INFO"))
|
||||
handler = StreamHandler()
|
||||
formatter = Formatter(
|
||||
"%(asctime)s - %(name)s - %(levelname)s - %(message)s")
|
||||
handler.setFormatter(formatter)
|
||||
|
||||
logger.addHandler(handler)
|
||||
|
||||
self.logger = logger
|
||||
|
||||
def handle_acquired_tags(self, acquired):
|
||||
"""
|
||||
Handles the acquired tags by subscribing to them if available.
|
||||
@@ -150,22 +127,23 @@ class Ingestor:
|
||||
"""
|
||||
|
||||
self.ingestor_manager = IngestorManager(
|
||||
self.kafka_servers,
|
||||
{
|
||||
kafka_servers=self.kafka_servers,
|
||||
redis_config={
|
||||
'host': self.redis_host,
|
||||
'port': self.redis_port,
|
||||
'username': self.redis_username,
|
||||
'password': self.redis_password,
|
||||
},
|
||||
self.lease_ttl,
|
||||
self.heartbeat_ttl,
|
||||
self.pod_id,
|
||||
self.poll_interval,
|
||||
self.mongo_connection_string,
|
||||
self.mongo_database,
|
||||
self.logger,
|
||||
self.notification_handler,
|
||||
self.export_to_kafka,
|
||||
lease_ttl=self.lease_ttl,
|
||||
heartbeat_ttl=self.heartbeat_ttl,
|
||||
pod_id=self.pod_id,
|
||||
poll_interval=self.poll_interval,
|
||||
mongo_connection_string=self.mongo_connection_string,
|
||||
mongo_database=self.mongo_database,
|
||||
metadata=self.metadata,
|
||||
logger=self.logger,
|
||||
notification_handler=self.notification_handler,
|
||||
export_to_kafka=self.export_to_kafka,
|
||||
)
|
||||
|
||||
# Declare ingestor ative
|
||||
|
||||
Reference in New Issue
Block a user