SIENTIAPDE-1184

fix: enhance error reporting in Formatters class

- Updated the parse_report_schedule method to return a dictionary for error keys, including both message and attachment.
- Improved error report formatting in send_error_report method to include attachments for better context in failure notifications.
This commit is contained in:
vitor-aignosi
2025-08-14 08:50:21 -03:00
parent 4d75d581f8
commit e8ce3e75d5
4 changed files with 109 additions and 40 deletions

View File

@@ -336,12 +336,15 @@ class Formatters(BaseActivity):
attachment_content=json.dumps(attachment, indent=4, sort_keys=True)
)
def parse_report_schedule(self, input_data: dict[str, Any]) -> tuple[list[str], list[str]]:
def parse_report_schedule(self, input_data: dict[str, Any]) -> tuple[list[str], dict[str, Any]]:
success_keys = [f"{value['namespace']}/{value['schedule_name']}"
for value in input_data if value['success']]
error_keys = [f"{value['namespace']}/{value['schedule_name']}: {value['message']}"
for value in input_data if not value['success']]
error_keys = {f"{value['namespace']}/{value['schedule_name']}": {
'message': value['message'],
'attachment': value.get('attachment', None)
}
for value in input_data if not value['success']}
return success_keys, error_keys
@@ -384,15 +387,24 @@ class Formatters(BaseActivity):
self.send_success_report(
metadata=metadata,
message=f"Created schedules: \n {', '.join(success_keys)}",
notification_id="REPORT_ORCHESTRATION_CREATED_SCHEDULES"
notification_id="REPORT_ORCHESTRATION_CREATED_SCHEDULES",
attachment=created_schedules
)
if len(error_keys) > 0:
attachment = []
for value in error_keys.values():
if value['attachment'] is not None:
attachment.append(
f"{value['message']}\n{value['attachment']}")
else:
attachment.append(value['message'])
self.send_error_report(
metadata=metadata,
message=f"Failed to create schedules: \n {', '.join(error_keys)}",
notification_id="REPORT_ORCHESTRATION_CREATED_SCHEDULES_ERROR",
attachment=created_schedules
attachment="\n ========== \n".join(attachment)
)
# Send report for updated schedules
@@ -404,15 +416,24 @@ class Formatters(BaseActivity):
self.send_success_report(
metadata=metadata,
message=f"Updated schedules: \n {', '.join(success_keys)}",
notification_id="REPORT_ORCHESTRATION_UPDATED_SCHEDULES"
notification_id="REPORT_ORCHESTRATION_UPDATED_SCHEDULES",
attachment=updated_schedules
)
if len(error_keys) > 0:
attachment = []
for value in error_keys.values():
if value['attachment'] is not None:
attachment.append(
f"{value['message']}\n{value['attachment']}")
else:
attachment.append(value['message'])
self.send_error_report(
metadata=metadata,
message=f"Failed to update schedules: \n {', '.join(error_keys)}",
notification_id="REPORT_ORCHESTRATION_UPDATED_SCHEDULES_ERROR",
attachment=updated_schedules
attachment="\n ========== \n".join(attachment)
)
if len(deleted_schedules) > 0:
@@ -423,15 +444,24 @@ class Formatters(BaseActivity):
self.send_success_report(
metadata=metadata,
message=f"Deleted schedules: \n {', '.join(success_keys)}",
notification_id="REPORT_ORCHESTRATION_DELETED_SCHEDULES"
notification_id="REPORT_ORCHESTRATION_DELETED_SCHEDULES",
attachment=deleted_schedules
)
if len(error_keys) > 0:
attachment = []
for value in error_keys.values():
if value['attachment'] is not None:
attachment.append(
f"{value['message']}\n{value['attachment']}")
else:
attachment.append(value['message'])
self.send_error_report(
metadata=metadata,
message=f"Failed to delete schedules: \n {', '.join(error_keys)}",
notification_id="REPORT_ORCHESTRATION_DELETED_SCHEDULES_ERROR",
attachment=deleted_schedules
attachment="\n ========== \n".join(attachment)
)
@activity.defn(name="report_slot_orchestration")