Skip to content

Commit

Permalink
fix cluster tasks UI (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k authored Jul 15, 2024
1 parent 2326abd commit aab4e18
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
13 changes: 9 additions & 4 deletions web/api/webrpc/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,28 @@ package webrpc

import (
"context"
"time"

"github.com/samber/lo"

"github.com/filecoin-project/curio/harmony/harmonytask"
)

type TaskSummary struct {
MinerID string
ID int64
Name string
SincePosted string
MinerID string
SincePosted time.Time `db:"since_posted"`
Owner, OwnerID *string
ID int64

// db ignored
SincePostedStr string `db:"-"`
}

func (a *WebRPC) ClusterTaskSummary(ctx context.Context) ([]TaskSummary, error) {
var ts []TaskSummary
err := a.deps.DB.Select(ctx, &ts, `SELECT
t.id as id, t.name as name, t.update_time as SincePosted, t.owner_id as owner_id, hm.host_and_port as owner
t.id as id, t.name as name, t.update_time as since_posted, t.owner_id as owner_id, hm.host_and_port as owner
FROM harmony_task t LEFT JOIN curio.harmony_machines hm ON hm.id = t.owner_id
ORDER BY t.update_time ASC, t.owner_id`)
if err != nil {
Expand All @@ -37,6 +41,7 @@ func (a *WebRPC) ClusterTaskSummary(ctx context.Context) ([]TaskSummary, error)
}
}
}

return ts, nil
}

Expand Down
15 changes: 7 additions & 8 deletions web/static/cluster-tasks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ class ClusterTasks extends LitElement {
}

async loadData() {
this.data = await RPCCall('ClusterTasks');
///hapi/simpleinfo/tasks
this.data = await RPCCall('ClusterTaskSummary');
setTimeout(() => this.loadData(), 1000);
super.requestUpdate();
}
Expand All @@ -36,11 +35,11 @@ class ClusterTasks extends LitElement {
<tbody>
${this.data.map(entry => html`
<tr>
<td>${this.MinerID? this.MinerID: ''}</td>
<td>${this.Name}</td>
<td>${this.ID}</td>
<td>${this.SincePosted}</td>
<td>${!this.OwnerID ? html`<a href="/hapi/node/{{.OwnerID}}">{{.Owner}}</a>{{end}}</td>`:''}
<td>${entry.MinerID? entry.MinerID: ''}</td>
<td>${entry.Name}</td>
<td>${entry.ID}</td>
<td>${entry.SincePosted}</td>
<td>${entry.OwnerID ? html`<a href="/hapi/node/${entry.OwnerID}">${entry.Owner}</a>`:''}</td>
</tr>
`)}
</tbody>
Expand All @@ -49,4 +48,4 @@ class ClusterTasks extends LitElement {
}
}

customElements.define('storage-gc-stats', StorageGCStats);
customElements.define('cluster-tasks', ClusterTasks);

0 comments on commit aab4e18

Please sign in to comment.