SIENTIAPDE-1172
refactor: update email HTML structure and enhance notification generator - Modified email HTML to reflect updated model names and error/warning messages. - Adjusted notification generator to improve execution counts and streamline output handling. - Refactored activities in orchestrator to correct parameter names and improve type hints for better clarity. - Enhanced email builder to handle error, warning, and info models more efficiently.
This commit is contained in:
@@ -73,9 +73,9 @@ class Activities( # Couchbase,
|
||||
Postgres.__init__(self,
|
||||
host=postgres_config['host'],
|
||||
port=postgres_config['port'],
|
||||
user=postgres_config['username'],
|
||||
user=postgres_config['user'],
|
||||
password=postgres_config['password'],
|
||||
dbname=postgres_config['database_name'],
|
||||
dbname=postgres_config['dbname'],
|
||||
min_connections=postgres_config['min_connections'],
|
||||
max_connections=postgres_config['max_connections'],
|
||||
logger=logger,
|
||||
|
||||
@@ -39,7 +39,7 @@ class Email(BaseActivity):
|
||||
notification_handler=notification_handler)
|
||||
|
||||
@activity.defn(name="build_email_html")
|
||||
async def build_email_html(self, input_data: dict[str, Any]) -> str:
|
||||
async def build_email_html(self, input_data: dict[str, Any]) -> dict[str, Any]:
|
||||
"""
|
||||
Builds the email html for each receiver group.
|
||||
input_data:
|
||||
|
||||
@@ -318,7 +318,7 @@ class SlotManager(Redis):
|
||||
return receiver_groups
|
||||
|
||||
@activity.defn(name="store_notification_cache")
|
||||
async def store_notification_cache(self, input_data: dict[str, Any]) -> dict[str, Any]:
|
||||
async def store_notification_cache(self, input_data: dict[str, Any]) -> None:
|
||||
"""
|
||||
Store notification cache
|
||||
"""
|
||||
@@ -335,5 +335,3 @@ class SlotManager(Redis):
|
||||
if status == 'sent':
|
||||
key = f"{row['schedule']}:{row['notification_id']}"
|
||||
self.set(key, now, ttl=sent_ttl)
|
||||
|
||||
return log_report
|
||||
|
||||
@@ -24,14 +24,18 @@ class EmailBuilder:
|
||||
return template.render(parameters)
|
||||
|
||||
def parameters(self, general_events: dict, mail_type: str) -> dict:
|
||||
error_models = general_events.get('ERROR', {}).get('models', [])
|
||||
warning_models = general_events.get('WARNING', {}).get('models', [])
|
||||
info_models = general_events.get('INFO', {}).get('models', [])
|
||||
|
||||
return {
|
||||
'mail_type': mail_type,
|
||||
'error_events': self.replace_parameters(self.general_template,
|
||||
general_events['ERROR']) if general_events['ERROR']['models'] else '',
|
||||
error_models) if error_models else '',
|
||||
'warning_events': self.replace_parameters(self.general_template,
|
||||
general_events['WARNING']) if general_events['WARNING']['models'] else '',
|
||||
warning_models) if warning_models else '',
|
||||
'info_events': self.replace_parameters(self.general_template,
|
||||
general_events['INFO']) if general_events['INFO']['models'] else '',
|
||||
info_models) if info_models else '',
|
||||
}
|
||||
|
||||
def build_email(self, report_data: list[dict], mail_type: str) -> str:
|
||||
|
||||
@@ -3,6 +3,8 @@ from temporalio import workflow
|
||||
with workflow.unsafe.imports_passed_through():
|
||||
from orchestrator.activities.activities import Activities
|
||||
from typing import Any
|
||||
from datetime import timedelta
|
||||
from sientia_do.temporal.utils.policies import retry_policy
|
||||
|
||||
|
||||
@workflow.defn(name="alerts")
|
||||
@@ -62,7 +64,9 @@ class Alerts:
|
||||
'notification_package': package['notification_package'],
|
||||
'sending_configs': package['sending_configs'],
|
||||
'notification_ttl': input_data['notification_ttl']
|
||||
}
|
||||
},
|
||||
schedule_to_close_timeout=timedelta(seconds=60),
|
||||
retry_policy=retry_policy
|
||||
)
|
||||
|
||||
# Call subworkflow "process_notifications" passing the notification package
|
||||
@@ -84,5 +88,7 @@ class Alerts:
|
||||
**metadata,
|
||||
'log_report': log_report,
|
||||
'sent_ttl': input_data['sent_ttl']
|
||||
}
|
||||
},
|
||||
schedule_to_close_timeout=timedelta(seconds=60),
|
||||
retry_policy=retry_policy
|
||||
)
|
||||
|
||||
@@ -75,6 +75,15 @@ class LoadNotificationPackage:
|
||||
'sending_configs': await sending_configs_handler
|
||||
}
|
||||
|
||||
sending_configs = await sending_configs_handler
|
||||
|
||||
if not sending_configs or not notification_package:
|
||||
return {
|
||||
'last_timestamp': last_timestamp,
|
||||
'notification_package': notification_package,
|
||||
'sending_configs': sending_configs
|
||||
}
|
||||
|
||||
# Put last collected timestamp in redis "notification_last_timestamp"
|
||||
|
||||
await workflow.start_activity_method(
|
||||
|
||||
@@ -42,7 +42,8 @@ class ProcessNotifications:
|
||||
Activities.build_email_html,
|
||||
{
|
||||
**metadata,
|
||||
"receiver_groups": input_data["notification_package"]
|
||||
"receiver_groups": input_data["notification_package"],
|
||||
"mail_type": input_data["mail_type"]
|
||||
},
|
||||
schedule_to_close_timeout=timedelta(seconds=60),
|
||||
retry_policy=retry_policy
|
||||
@@ -68,6 +69,8 @@ class ProcessNotifications:
|
||||
"receiver_groups": log_report,
|
||||
"mail_type": input_data["mail_type"]
|
||||
},
|
||||
schedule_to_close_timeout=timedelta(seconds=60),
|
||||
retry_policy=retry_policy
|
||||
)
|
||||
|
||||
# Store sending log in postgres database "log_report"
|
||||
|
||||
Reference in New Issue
Block a user