Skip to content

Commit c25dd4c

Browse files
Improve display of run details on the status page
How this addresses that need: * Provide summary of task run and encapsulate logs within textbox Side effects of this change: * None Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/IN-1066
1 parent c8e50f7 commit c25dd4c

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

tests/test_aws/test_cloudwatch.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,27 @@ def test_cloudwatchlogs_client_get_log_messages_review_run_success(
1616
cloudwatch_sapinvoices_review_run_logs,
1717
mock_cloudwatchlogs_log_stream_review_run_task,
1818
):
19-
assert (
20-
cloudwatchlogs_client.get_log_messages(task_id="abc001")
21-
== cloudwatch_sapinvoices_review_run_logs
22-
)
19+
assert cloudwatchlogs_client.get_log_messages(task_id="abc001") == [
20+
"INFO sapinvoices.cli.process_invoices(): SAP invoice process completed for a review run", # noqa: E501
21+
"3 monograph invoices retrieved and processed:",
22+
"2 SAP monograph invoices",
23+
"1 other payment monograph invoices",
24+
"2 serial invoices retrieved and processed",
25+
]
2326

2427

2528
def test_cloudwatchlogs_client_get_log_messages_final_run_success(
2629
cloudwatchlogs_client,
2730
cloudwatch_sapinvoices_final_run_logs,
2831
mock_cloudwatchlogs_log_stream_final_run_task,
2932
):
30-
assert (
31-
cloudwatchlogs_client.get_log_messages(task_id="abc002")
32-
== cloudwatch_sapinvoices_final_run_logs
33-
)
33+
assert cloudwatchlogs_client.get_log_messages(task_id="abc002") == [
34+
"INFO sapinvoices.cli.process_invoices(): SAP invoice process completed for a final run", # noqa: E501
35+
"3 monograph invoices retrieved and processed:",
36+
"2 SAP monograph invoices",
37+
"1 other payment monograph invoices",
38+
"2 serial invoices retrieved and processed",
39+
]
3440

3541

3642
def test_cloudwatchlogs_client_get_log_events_raise_error(

webapp/static/libraries-additional.min.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
.box-content {
2+
display: inline-block;
3+
}
4+
15
.platform-name {
26
color: #fff;
37
font-size: clamp(1rem,5vw,2.8rem);

webapp/utils/aws/cloudwatch.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,29 @@ def client(self) -> "CloudWatchLogsClientType":
3939
def get_log_messages(self, task_id: str) -> list:
4040
messages: list = []
4141
if logs := self.get_log_events(task_id):
42-
messages.extend(event["message"] for event in logs)
42+
return self.get_log_summary(logs)
4343
return messages
4444

45+
def get_log_summary(self, logs: list[dict]) -> list[str]:
46+
"""Get summary of SAP invoice processing logs.
47+
48+
This function will first determine the index of the log event
49+
the marks the start of the "summary" log messages that
50+
describe the output of the SAP invoice processing run.
51+
The function will then retrieve all the messages starting from
52+
that index, effectively retrieving a summary of the run.
53+
"""
54+
summary_index: int | None = None
55+
for index, event in enumerate(logs):
56+
message = event["message"]
57+
if (
58+
"SAP invoice process completed" in message
59+
or "No invoices waiting to be sent in Alma" in message
60+
):
61+
summary_index = index
62+
return [event["message"] for event in logs[summary_index:]]
63+
return ["SAP invoice process did not complete."]
64+
4565
def get_log_events(self, task_id: str) -> list:
4666
logger.info("Retrieving CloudWatch logs for task.")
4767
log_events = []

0 commit comments

Comments
 (0)