Skip to content

Commit 6b0f5d1

Browse files
authored
webui: Always show recent task fails in the task page (#171)
1 parent 01991d1 commit 6b0f5d1

File tree

3 files changed

+75
-3
lines changed

3 files changed

+75
-3
lines changed

web/api/webrpc/harmony_stats.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ type HarmonyTaskHistory struct {
6868
CompletedByName *string `db:"completed_by_machine_name"`
6969
}
7070

71-
func (a *WebRPC) HarmonyTaskHistory(ctx context.Context, taskName string) ([]HarmonyTaskHistory, error) {
71+
func (a *WebRPC) HarmonyTaskHistory(ctx context.Context, taskName string, fails bool) ([]HarmonyTaskHistory, error) {
7272
var stats []HarmonyTaskHistory
7373
err := a.deps.DB.Select(ctx, &stats, `SELECT
7474
hist.task_id, hist.name, hist.work_start, hist.work_end, hist.posted, hist.result, hist.err,
7575
hist.completed_by_host_and_port, mach.id as completed_by_machine, hmd.machine_name as completed_by_machine_name
7676
FROM harmony_task_history hist
7777
LEFT JOIN harmony_machines mach ON hist.completed_by_host_and_port = mach.host_and_port
7878
LEFT JOIN curio.harmony_machine_details hmd on mach.id = hmd.machine_id
79-
WHERE name = $1 AND work_end > current_timestamp - interval '1 day' ORDER BY work_end DESC LIMIT 30`, taskName)
79+
WHERE name = $1 AND work_end > current_timestamp - interval '1 day' AND ($2 OR NOT hist.result) ORDER BY work_end DESC LIMIT 30`, taskName, !fails)
8080
if err != nil {
8181
return nil, err
8282
}

web/static/task/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ <h4>History</h4>
3131
</div>
3232
</div>
3333
</section>
34+
<section class="section">
35+
<div class="row">
36+
<div class="col-md-auto" style="max-width: 95%">
37+
<h4>Recent Failures</h4>
38+
<harmony-task-fails></harmony-task-fails>
39+
</div>
40+
</div>
41+
</section>
3442
</curio-ux>
3543
</body>
3644

web/static/task/task-history.mjs

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class HarmonyTaskHistoryTable extends LitElement {
1111

1212
async loadHistory() {
1313
try {
14-
this.history = await RPCCall('HarmonyTaskHistory', [this.taskName]);
14+
this.history = await RPCCall('HarmonyTaskHistory', [this.taskName, false]);
1515
this.requestUpdate();
1616
} catch (error) {
1717
console.error('Error fetching task history data:', error);
@@ -63,3 +63,67 @@ class HarmonyTaskHistoryTable extends LitElement {
6363
}
6464

6565
customElements.define('harmony-task-history', HarmonyTaskHistoryTable);
66+
67+
class HarmonyTaskFailsTable extends LitElement {
68+
constructor() {
69+
super();
70+
this.history = [];
71+
this.taskName = new URLSearchParams(window.location.search).get('name');
72+
this.loadHistory();
73+
}
74+
75+
async loadHistory() {
76+
try {
77+
this.history = await RPCCall('HarmonyTaskHistory', [this.taskName, true]);
78+
this.requestUpdate();
79+
} catch (error) {
80+
console.error('Error fetching task history data:', error);
81+
}
82+
}
83+
84+
static get styles() {
85+
return css`
86+
.error {
87+
color: red;
88+
}
89+
`;
90+
}
91+
92+
render() {
93+
return html`
94+
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
95+
<link rel="stylesheet" href="/ux/main.css" onload="document.body.style.visibility = 'initial'">
96+
<table class="table table-dark">
97+
<thead>
98+
<tr>
99+
<th>Task ID</th>
100+
<th>Name</th>
101+
<th>Work Start</th>
102+
<th>Work End</th>
103+
<th>Posted</th>
104+
<th>Completed By</th>
105+
<th>Result</th>
106+
<th>Error</th>
107+
</tr>
108+
</thead>
109+
<tbody>
110+
${this.history.map(task => html`
111+
<tr>
112+
<td>${task.TaskID}</td>
113+
<td>${task.Name}</td>
114+
<td>${new Date(task.WorkStart).toLocaleString()}</td>
115+
<td>${new Date(task.WorkEnd).toLocaleString()}</td>
116+
<td>${new Date(task.Posted).toLocaleString()}</td>
117+
<td>${task.CompletedById ? html`<a href="/pages/node_info/?id=${task.CompletedById}">${task.CompletedByName} (${task.CompletedBy})</a>` : task.CompletedBy}</td>
118+
<td class="${task.Result ? '' : 'error'}">${task.Result ? 'Success' : 'Failed'}</td>
119+
<td>${task.Err}</td>
120+
</tr>
121+
`)}
122+
</tbody>
123+
</table>
124+
`;
125+
}
126+
}
127+
128+
customElements.define('harmony-task-fails', HarmonyTaskFailsTable);
129+

0 commit comments

Comments
 (0)