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:
@@ -3,9 +3,13 @@ from typing import List
|
||||
from redis import Redis
|
||||
from time import time
|
||||
import ingestor.metrics as metrics
|
||||
from sientia_do.notifications.handlers import CoreNotificationHandler as NotificationHandler
|
||||
from sientia_do.notifications.models import NotificationLevel
|
||||
from sientia_do.temporal.utils.logger import Logger
|
||||
from sientia_do.temporal.activities.base import BaseActivity
|
||||
|
||||
|
||||
class ResourceManager:
|
||||
class ResourceManager(BaseActivity):
|
||||
def __init__(
|
||||
self,
|
||||
host: str,
|
||||
@@ -13,6 +17,9 @@ class ResourceManager:
|
||||
lease_ttl: int,
|
||||
heartbeat_ttl: int,
|
||||
pod_id: str,
|
||||
metadata: dict,
|
||||
logger: Logger,
|
||||
notification_handler: NotificationHandler,
|
||||
username: str | None = None,
|
||||
password: str | None = None,
|
||||
) -> None:
|
||||
@@ -28,12 +35,16 @@ class ResourceManager:
|
||||
self.redis.ping()
|
||||
metrics.REDIS_CONNECTION_STATUS.labels(pod_id=self.pod_id).set(1)
|
||||
except Exception as e:
|
||||
print(f"Failed to connect to Redis: {e}")
|
||||
logger.error(f"Failed to connect to Redis: {e}")
|
||||
metrics.REDIS_CONNECTION_STATUS.labels(pod_id=self.pod_id).set(0)
|
||||
raise
|
||||
|
||||
self.lease_ttl = lease_ttl
|
||||
self.heartbeat_ttl = heartbeat_ttl
|
||||
self.metadata = metadata
|
||||
|
||||
BaseActivity.__init__(self, logger=logger,
|
||||
notification_handler=notification_handler)
|
||||
|
||||
def _execute_redis_op(self, operation_name: str, func, *args, **kwargs):
|
||||
"""Wrapper to execute Redis operations and record metrics."""
|
||||
@@ -52,7 +63,13 @@ class ResourceManager:
|
||||
metrics.REDIS_OPERATIONS_ERRORS.labels(
|
||||
pod_id=self.pod_id, operation=operation_name
|
||||
).inc()
|
||||
print(f"Error in Redis operation '{operation_name}': {e}")
|
||||
self.send_notification(
|
||||
metadata=self.metadata,
|
||||
notification_id=f"REDIS_OPERATION_ERROR_{operation_name}",
|
||||
message=f"Error in Redis operation '{operation_name}': {e}",
|
||||
block="redis_manager",
|
||||
level=NotificationLevel.ERROR,
|
||||
)
|
||||
raise
|
||||
|
||||
def get(self, key: str) -> dict:
|
||||
@@ -151,7 +168,8 @@ class ResourceManager:
|
||||
None
|
||||
"""
|
||||
|
||||
self._execute_redis_op("delete", self.redis.delete, f"lease:opc_tags:{tag_id}")
|
||||
self._execute_redis_op("delete", self.redis.delete,
|
||||
f"lease:opc_tags:{tag_id}")
|
||||
|
||||
def get_all_ingestors(self) -> List[str]:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user