Skip to content

Commit fb6b19d

Browse files
authored
feat(notifications): improve hardware summary code (#1645)
- Send weekly hardware summary emails instead of only on failures - Restrict notifications to production or dev environments Signed-off-by: Yushan Li <[email protected]>
1 parent 581747d commit fb6b19d

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

backend/kernelCI_app/management/commands/notifications.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -739,9 +739,12 @@ def generate_hardware_summary_report(
739739
):
740740
"""
741741
Generate weekly hardware reports for hardware submission file.
742-
Emails are sent only for hardware with failed tests.
743742
"""
744743

744+
if get_running_instance() == "staging":
745+
print("This command only runs on production or dev environments.")
746+
return
747+
745748
now = datetime.now(timezone.utc)
746749
start_date = now - timedelta(days=7)
747750
end_date = now
@@ -759,10 +762,6 @@ def generate_hardware_summary_report(
759762
end_date=end_date,
760763
)
761764

762-
if not hardwares_data_raw:
763-
print("No data for hardware summary")
764-
return
765-
766765
hardwares_data_dict = defaultdict(list)
767766
for raw in hardwares_data_raw:
768767
try:
@@ -786,11 +785,15 @@ def generate_hardware_summary_report(
786785
)
787786

788787
# Iterate through each hardware record to render report, extract recipient, send email
789-
for (hardware_id, origin), hardware_data in hardwares_data_dict.items():
788+
for hardware_id, origin in hardware_key_set:
789+
hardware_data = hardwares_data_dict.get((hardware_id, origin), [])
790790
hardware_raw = next(
791791
(row for row in hardwares_list_raw if row.get("platform") == hardware_id),
792792
None,
793793
)
794+
if hardware_raw is None:
795+
print(f"Hardware {hardware_id} not found in listing data")
796+
continue
794797

795798
hardware_item = sanitize_hardware(hardware_raw)
796799
build_status_group = group_status(hardware_item.build_status_summary)

docs/notifications.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ The command supports four primary actions:
2727
1. `summary`
2828
* Runs a checkout summary report for trees listed in the [subscriptions folder](../backend/data/notifications/subscriptions/).
2929
1. `hardware_summary`
30-
* Generate weekly hardware reports for hardware listed in the [subscriptions folder](../backend/data/notifications/subscriptions/). Emails are sent only for hardware with failed tests.
30+
* Generate weekly hardware reports for hardware listed in the [subscriptions folder](../backend/data/notifications/subscriptions/).
3131
1. `fake_report`
3232
* Generates a fake report (for testing email send).
3333

0 commit comments

Comments
 (0)