SIENTIAPDE-1172
feat: integrate email configuration and enhance orchestrator activities - Added email configuration parameters to values.yaml for sender details and SMTP settings. - Refactored Email class to correct parameter names and improve logging during initialization. - Introduced build_email_config function to streamline email configuration retrieval. - Updated worker.py to include email and Postgres configurations in the main orchestration process.
This commit is contained in:
@@ -1,14 +1,12 @@
|
|||||||
from temporalio import activity, workflow
|
from temporalio import workflow
|
||||||
from temporalio.client import Client
|
|
||||||
|
|
||||||
from orchestrator.activities.email import Email
|
|
||||||
from orchestrator.activities.mongo_db import MongoDB
|
|
||||||
|
|
||||||
with workflow.unsafe.imports_passed_through():
|
with workflow.unsafe.imports_passed_through():
|
||||||
from orchestrator.activities.couchbase import Couchbase
|
|
||||||
from orchestrator.activities.temporal_manager import TemporalManager
|
from orchestrator.activities.temporal_manager import TemporalManager
|
||||||
from orchestrator.activities.slot_manager import SlotManager
|
from orchestrator.activities.slot_manager import SlotManager
|
||||||
from orchestrator.activities.formatters import Formatters
|
from orchestrator.activities.formatters import Formatters
|
||||||
|
from orchestrator.activities.email import Email
|
||||||
|
from orchestrator.activities.mongo_db import MongoDB
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from logging import Logger
|
from logging import Logger
|
||||||
from sientia_do.temporal.activities.postgres import Postgres
|
from sientia_do.temporal.activities.postgres import Postgres
|
||||||
@@ -67,8 +65,8 @@ class Activities( # Couchbase,
|
|||||||
Email.__init__(self,
|
Email.__init__(self,
|
||||||
sender_email=email_config['sender_email'],
|
sender_email=email_config['sender_email'],
|
||||||
sender_password=email_config['sender_password'],
|
sender_password=email_config['sender_password'],
|
||||||
smpt_server=email_config['smpt_server'],
|
smtp_server=email_config['smtp_server'],
|
||||||
port=email_config['port'],
|
smtp_port=email_config['smtp_port'],
|
||||||
logger=logger,
|
logger=logger,
|
||||||
notification_handler=notification_handler)
|
notification_handler=notification_handler)
|
||||||
|
|
||||||
|
|||||||
@@ -17,20 +17,22 @@ with workflow.unsafe.imports_passed_through():
|
|||||||
|
|
||||||
class Email(BaseActivity):
|
class Email(BaseActivity):
|
||||||
def __init__(self, sender_email: str, sender_password: str,
|
def __init__(self, sender_email: str, sender_password: str,
|
||||||
smpt_server: str, port: int,
|
smtp_server: str, smtp_port: int,
|
||||||
logger: Logger, notification_handler: NotificationHandler):
|
logger: Logger, notification_handler: NotificationHandler):
|
||||||
|
|
||||||
self.email_builder = EmailBuilder(logger=logger)
|
self.email_builder = EmailBuilder(logger=logger)
|
||||||
|
|
||||||
self.sender_email = sender_email
|
self.sender_email = sender_email
|
||||||
self.sender_password = sender_password
|
self.sender_password = sender_password
|
||||||
self.port = port
|
self.smtp_port = smtp_port
|
||||||
|
|
||||||
|
logger.info(f"Initializing Email with {smtp_server}:{smtp_port}")
|
||||||
|
|
||||||
|
self.server = smtplib.SMTP(smtp_server, smtp_port)
|
||||||
|
|
||||||
if self.sender_password:
|
if self.sender_password:
|
||||||
self.server = smtplib.SMTP_SSL(smpt_server, port)
|
self.server.starttls()
|
||||||
self.server.login(self.sender_email, self.sender_password)
|
self.server.login(self.sender_email, self.sender_password)
|
||||||
else:
|
|
||||||
self.server = smtplib.SMTP(smpt_server, port)
|
|
||||||
|
|
||||||
BaseActivity.__init__(self,
|
BaseActivity.__init__(self,
|
||||||
logger=logger,
|
logger=logger,
|
||||||
|
|||||||
@@ -38,3 +38,24 @@ def build_temporal_config():
|
|||||||
'temporal_scouter_namespace': getenv('TEMPORAL_SCOUTER_NAMESPACE', 'scouter'),
|
'temporal_scouter_namespace': getenv('TEMPORAL_SCOUTER_NAMESPACE', 'scouter'),
|
||||||
'temporal_laborious_namespace': getenv('TEMPORAL_LABORIOUS_NAMESPACE', 'laborious')
|
'temporal_laborious_namespace': getenv('TEMPORAL_LABORIOUS_NAMESPACE', 'laborious')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def build_postgres_config():
|
||||||
|
return {
|
||||||
|
'host': getenv('POSTGRES_HOST', 'localhost'),
|
||||||
|
'port': int(getenv('POSTGRES_PORT', '5432')),
|
||||||
|
'user': getenv('POSTGRES_USER', 'sientia'),
|
||||||
|
'password': getenv('POSTGRES_PASSWORD', 'sientia'),
|
||||||
|
'dbname': getenv('POSTGRES_DBNAME', 'sientia'),
|
||||||
|
'min_connections': int(getenv('POSTGRES_MIN_CONNECTIONS', '5')),
|
||||||
|
'max_connections': int(getenv('POSTGRES_MAX_CONNECTIONS', '20'))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def build_email_config():
|
||||||
|
return {
|
||||||
|
'sender_email': getenv('EMAIL_SENDER', 'sientia-alerts@aignosi.com'),
|
||||||
|
'sender_password': getenv('EMAIL_SENDER_PASSWORD', 'sientia'),
|
||||||
|
'smtp_server': getenv('EMAIL_SMTP_SERVER', 'smtp.gmail.com'),
|
||||||
|
'smtp_port': int(getenv('EMAIL_SMTP_PORT', '587'))
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,18 +1,23 @@
|
|||||||
from temporalio import workflow, client
|
from temporalio import workflow, client
|
||||||
from temporalio.worker import Worker
|
from temporalio.worker import Worker
|
||||||
|
|
||||||
from orchestrator.utils.connectors_config import build_temporal_config
|
|
||||||
|
|
||||||
with workflow.unsafe.imports_passed_through():
|
with workflow.unsafe.imports_passed_through():
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import asyncio
|
import asyncio
|
||||||
|
from orchestrator.workflows.alerts import Alerts
|
||||||
|
from orchestrator.workflows.subworkflows.load_notification_package import LoadNotificationPackage
|
||||||
|
from orchestrator.workflows.subworkflows.process_notifications import ProcessNotifications
|
||||||
from orchestrator.workflows.orchestrator import Orchestrator
|
from orchestrator.workflows.orchestrator import Orchestrator
|
||||||
from orchestrator.activities.activities import Activities
|
from orchestrator.activities.activities import Activities
|
||||||
from orchestrator.utils.connectors_config import (
|
from orchestrator.utils.connectors_config import (
|
||||||
# build_couchbase_config,
|
# build_couchbase_config,
|
||||||
build_redis_config,
|
build_redis_config,
|
||||||
build_mongodb_config
|
build_mongodb_config,
|
||||||
|
build_temporal_config,
|
||||||
|
build_email_config,
|
||||||
|
build_postgres_config
|
||||||
)
|
)
|
||||||
from sientia_do.notifications.handlers import CoreNotificationHandler as NotificationHandler
|
from sientia_do.notifications.handlers import CoreNotificationHandler as NotificationHandler
|
||||||
from sientia_do.temporal.utils.logger import get_logger
|
from sientia_do.temporal.utils.logger import get_logger
|
||||||
@@ -48,6 +53,8 @@ async def main():
|
|||||||
temporal_config=build_temporal_config(),
|
temporal_config=build_temporal_config(),
|
||||||
redis_config=build_redis_config(),
|
redis_config=build_redis_config(),
|
||||||
mongodb_config=build_mongodb_config(),
|
mongodb_config=build_mongodb_config(),
|
||||||
|
email_config=build_email_config(),
|
||||||
|
postgres_config=build_postgres_config(),
|
||||||
logger=logger,
|
logger=logger,
|
||||||
notification_handler=notification_handler
|
notification_handler=notification_handler
|
||||||
)
|
)
|
||||||
@@ -90,6 +97,30 @@ async def main():
|
|||||||
activities.report_slot_orchestration,
|
activities.report_slot_orchestration,
|
||||||
activities.format_schedule_config,
|
activities.format_schedule_config,
|
||||||
]
|
]
|
||||||
|
),
|
||||||
|
Worker(
|
||||||
|
temporal_client,
|
||||||
|
task_queue='alerts-queue',
|
||||||
|
workflows=[Alerts, LoadNotificationPackage, ProcessNotifications],
|
||||||
|
activities=[
|
||||||
|
# Load notifications
|
||||||
|
activities.get_last_data_timestamp,
|
||||||
|
activities.find_documents_in_mongodb,
|
||||||
|
activities.load_latest_data,
|
||||||
|
activities.put_last_data_timestamp,
|
||||||
|
|
||||||
|
# Format and filter notifications
|
||||||
|
activities.filter_notification_alerts,
|
||||||
|
|
||||||
|
# Send email and export data to postgres
|
||||||
|
activities.build_email_html,
|
||||||
|
activities.send_email,
|
||||||
|
activities.format_log_report,
|
||||||
|
activities.export_data_to_postgres,
|
||||||
|
|
||||||
|
# Store notification cache
|
||||||
|
activities.store_notification_cache
|
||||||
|
]
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
16
values.yaml
16
values.yaml
@@ -170,6 +170,18 @@ env:
|
|||||||
- name: MONGODB_TTL_INDEX_HOURS
|
- name: MONGODB_TTL_INDEX_HOURS
|
||||||
value: "1"
|
value: "1"
|
||||||
|
|
||||||
|
- name: EMAIL_SENDER
|
||||||
|
value: "sientia-alerts@aignosi.com"
|
||||||
|
- name: EMAIL_SENDER_PASSWORD
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: smtp-credentials
|
||||||
|
key: sender-password
|
||||||
|
- name: EMAIL_SMTP_SERVER
|
||||||
|
value: "smtp.gmail.com"
|
||||||
|
- name: EMAIL_SMTP_PORT
|
||||||
|
value: "587"
|
||||||
|
|
||||||
- name: KAFKA_BOOTSTRAP_SERVERS
|
- name: KAFKA_BOOTSTRAP_SERVERS
|
||||||
value: "kafka.kafka.svc.cluster.local:9092"
|
value: "kafka.kafka.svc.cluster.local:9092"
|
||||||
|
|
||||||
@@ -201,3 +213,7 @@ ssh:
|
|||||||
# --namespace sientia \
|
# --namespace sientia \
|
||||||
# --from-file=ssh-privatekey=git_key \
|
# --from-file=ssh-privatekey=git_key \
|
||||||
# --type=kubernetes.io/ssh-auth
|
# --type=kubernetes.io/ssh-auth
|
||||||
|
|
||||||
|
# kubectl create secret generic smtp-credentials \
|
||||||
|
# --namespace sientia \
|
||||||
|
# --from-literal=app_password='sua-senha-de-app-de-16-digitos'
|
||||||
Reference in New Issue
Block a user