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:
vitor-aignosi
2025-07-28 17:26:28 -03:00
parent 9bc238388a
commit c3ba2e4b5a
9 changed files with 184 additions and 172 deletions

View File

@@ -17,7 +17,7 @@
<h3>Errors detected:</h3>
<h4>Model: <span>ut aliqua ut ipsum</span></h4>
<h4>Model: <span>do elit</span></h4>
<table>
<thead>
<tr>
@@ -30,16 +30,16 @@
<tbody>
<tr>
<td>TAG_node5:tag_87_LISTENNING_STOPPED</td>
<td>dolor_elit_aliqua</td>
<td>2025-07-25 16:50:48.925421+00:00</td>
<td>sit elit ipsum labore incididunt magna do et sit incididunt</td>
<td>REPORT_PARTITION_MANAGER</td>
<td>lorem_adipiscing</td>
<td>2025-07-28 20:05:38.650661+00:00</td>
<td>incididunt dolor lorem incididunt elit incididunt dolor consectetur ipsum ut</td>
</tr>
</tbody>
</table>
<h4>Model: <span>elit dolore</span></h4>
<h4>Model: <span>dolor magna</span></h4>
<table>
<thead>
<tr>
@@ -52,16 +52,16 @@
<tbody>
<tr>
<td>OPC_LISTENNING_BACK__server_10</td>
<td>magna_magna_et</td>
<td>2025-07-25 16:50:48.925478+00:00</td>
<td>aliqua eiusmod ut eiusmod ut et ipsum</td>
<td>REPORT_PARTITION_MANAGER</td>
<td>tempor_dolore_eiusmod</td>
<td>2025-07-28 20:05:38.650910+00:00</td>
<td>ipsum amet ipsum aliqua et eiusmod</td>
</tr>
</tbody>
</table>
<h4>Model: <span>lorem lorem ipsum amet</span></h4>
<h4>Model: <span>labore sit lorem</span></h4>
<table>
<thead>
<tr>
@@ -74,10 +74,10 @@
<tbody>
<tr>
<td>TAG_node8:tag_11_LISTENNING_STOPPED</td>
<td>do_sit</td>
<td>2025-07-25 16:50:48.925506+00:00</td>
<td>labore do adipiscing adipiscing incididunt eiusmod</td>
<td>OPC_CONNECTION_RETRY__server_6</td>
<td>dolor_labore_lorem</td>
<td>2025-07-28 20:05:38.650949+00:00</td>
<td>et adipiscing ipsum ut aliqua ut adipiscing aliqua amet</td>
</tr>
</tbody>
@@ -85,7 +85,7 @@
<h3>Warnings detected:</h3>
<h4>Model: <span>amet eiusmod dolor ipsum</span></h4>
<h4>Model: <span>incididunt adipiscing elit sit</span></h4>
<table>
<thead>
<tr>
@@ -98,16 +98,16 @@
<tbody>
<tr>
<td>REPORT_PARTITION_MANAGER</td>
<td>adipiscing_amet_ut_et</td>
<td>2025-07-25 16:50:48.925368+00:00</td>
<td>eiusmod et amet sit lorem incididunt</td>
<td>ADIPISCING_AMET_IPSUM</td>
<td>eiusmod_aliqua_incididunt</td>
<td>2025-07-28 20:05:38.650621+00:00</td>
<td>magna incididunt dolore sed eiusmod sit incididunt ut</td>
</tr>
</tbody>
</table>
<h4>Model: <span>sit et labore</span></h4>
<h4>Model: <span>do adipiscing et</span></h4>
<table>
<thead>
<tr>
@@ -120,16 +120,16 @@
<tbody>
<tr>
<td>SIT_CONSECTETUR_EIUSMOD</td>
<td>adipiscing_elit_ut</td>
<td>2025-07-25 16:50:48.925392+00:00</td>
<td>magna do eiusmod et labore elit</td>
<td>TAG_node46:tag_73_LISTENNING_STOPPED</td>
<td>amet_dolor</td>
<td>2025-07-28 20:05:38.650706+00:00</td>
<td>dolore do et consectetur adipiscing do magna eiusmod eiusmod</td>
</tr>
</tbody>
</table>
<h4>Model: <span>consectetur labore do consectetur</span></h4>
<h4>Model: <span>lorem dolore amet</span></h4>
<table>
<thead>
<tr>
@@ -142,16 +142,16 @@
<tbody>
<tr>
<td>SED_SIT_DOLOR_CONSECTETUR</td>
<td>dolor_dolore_ut</td>
<td>2025-07-25 16:50:48.925435+00:00</td>
<td>magna sed incididunt dolor tempor</td>
<td>TAG_node13:tag_59_LISTENNING_STOPPED</td>
<td>ipsum_tempor_ipsum</td>
<td>2025-07-28 20:05:38.650785+00:00</td>
<td>et sed adipiscing tempor dolor magna do lorem</td>
</tr>
</tbody>
</table>
<h4>Model: <span>et sed ut et</span></h4>
<h4>Model: <span>eiusmod sed</span></h4>
<table>
<thead>
<tr>
@@ -164,10 +164,10 @@
<tbody>
<tr>
<td>UT_UT_LABORE</td>
<td>sit_do</td>
<td>2025-07-25 16:50:48.925492+00:00</td>
<td>do sed sed elit do eiusmod</td>
<td>OPC_SUBSCRIPTION__server_2</td>
<td>do_ipsum</td>
<td>2025-07-28 20:05:38.650826+00:00</td>
<td>eiusmod et consectetur do dolore dolor sed amet</td>
</tr>
</tbody>
@@ -175,7 +175,7 @@
<h3>Infos detected:</h3>
<h4>Model: <span>eiusmod eiusmod</span></h4>
<h4>Model: <span>et sed</span></h4>
<table>
<thead>
<tr>
@@ -188,16 +188,16 @@
<tbody>
<tr>
<td>OPC_CONNECTION_RETRY__server_2</td>
<td>labore_sit_do</td>
<td>2025-07-25 16:50:48.925407+00:00</td>
<td>magna et ipsum amet dolore adipiscing adipiscing do</td>
<td>OPC_LISTENNING_STOPPED__server_6</td>
<td>labore_do_ipsum_ipsum</td>
<td>2025-07-28 20:05:38.650570+00:00</td>
<td>tempor dolore eiusmod sit sit sed elit</td>
</tr>
</tbody>
</table>
<h4>Model: <span>adipiscing consectetur</span></h4>
<h4>Model: <span>dolore sit</span></h4>
<table>
<thead>
<tr>
@@ -211,15 +211,15 @@
<tr>
<td>REPORT_PARTITION_MANAGER</td>
<td>incididunt_aliqua_ipsum_ut</td>
<td>2025-07-25 16:50:48.925447+00:00</td>
<td>labore magna adipiscing tempor elit et et magna elit lorem</td>
<td>et_lorem_incididunt_ipsum</td>
<td>2025-07-28 20:05:38.650742+00:00</td>
<td>adipiscing magna adipiscing adipiscing sit tempor</td>
</tr>
</tbody>
</table>
<h4>Model: <span>et amet</span></h4>
<h4>Model: <span>adipiscing do</span></h4>
<table>
<thead>
<tr>
@@ -232,10 +232,10 @@
<tbody>
<tr>
<td>OPC_LISTENNING_BACK__server_2</td>
<td>sed_elit_ut_do</td>
<td>2025-07-25 16:50:48.925462+00:00</td>
<td>dolor et adipiscing adipiscing dolore ipsum ipsum aliqua et elit</td>
<td>TAG_node76:tag_73_LISTENNING_STOPPED</td>
<td>tempor_elit</td>
<td>2025-07-28 20:05:38.650875+00:00</td>
<td>et do aliqua lorem incididunt</td>
</tr>
</tbody>

File diff suppressed because one or more lines are too long

View File

@@ -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,

View File

@@ -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:

View File

@@ -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

View File

@@ -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:

View File

@@ -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
)

View File

@@ -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(

View File

@@ -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"