SIENTIAPDE-1174 Add pod_id initialization in Activities class and update Scouter to reference it for improved consistency in environment variable handling.
70 lines
2.3 KiB
Python
70 lines
2.3 KiB
Python
from temporalio import workflow
|
|
|
|
with workflow.unsafe.imports_passed_through():
|
|
from sientia_do.temporal.activities.postgres import Postgres
|
|
from sientia_do.notifications.handlers import CoreNotificationHandler as NotificationHandler
|
|
from sientia_do.temporal.utils.logger import Logger
|
|
from scouter.activities.redis import Redis
|
|
from scouter.activities.gates import Gates
|
|
from scouter.activities.mongodb import MongoDB
|
|
from typing import Any
|
|
from os import getenv
|
|
|
|
|
|
class Activities(Postgres, Redis, Gates, MongoDB,):
|
|
"""Activities class that combines multiple services with proper initialization."""
|
|
|
|
def __init__(self,
|
|
postgres_config: dict[str, Any],
|
|
redis_config: dict[str, Any],
|
|
mongodb_config: dict[str, Any],
|
|
logger: Logger,
|
|
notification_handler: NotificationHandler):
|
|
|
|
# Initialize Postgres
|
|
Postgres.__init__(
|
|
self,
|
|
host=postgres_config['host'],
|
|
port=postgres_config['port'],
|
|
user=postgres_config['user'],
|
|
password=postgres_config['password'],
|
|
dbname=postgres_config['dbname'],
|
|
min_connections=postgres_config['min_connections'],
|
|
max_connections=postgres_config['max_connections'],
|
|
logger=logger,
|
|
notification_handler=notification_handler
|
|
)
|
|
|
|
# Initialize Redis
|
|
Redis.__init__(
|
|
self,
|
|
host=redis_config['host'],
|
|
port=redis_config['port'],
|
|
logger=logger,
|
|
notification_handler=notification_handler,
|
|
username=redis_config['username'],
|
|
password=redis_config['password']
|
|
)
|
|
|
|
# Initialize Gates
|
|
Gates.__init__(
|
|
self,
|
|
logger=logger,
|
|
notification_handler=notification_handler
|
|
)
|
|
|
|
# Initialize MongoDB
|
|
MongoDB.__init__(
|
|
self,
|
|
connection_string=mongodb_config['connection_string'],
|
|
database_name=mongodb_config['database_name'],
|
|
logger=logger,
|
|
notification_handler=notification_handler
|
|
)
|
|
|
|
self.pod_id = getenv("HOSTNAME", "localhost")
|
|
|
|
def shutdown(self):
|
|
Postgres.close(self)
|
|
MongoDB.shutdown(self)
|