Skip to content

Commit

Permalink
add job id to UI
Browse files Browse the repository at this point in the history
  • Loading branch information
dma committed Jun 1, 2022
1 parent 36ee486 commit af00448
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
22 changes: 12 additions & 10 deletions cmd/ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,24 @@ <h2>status</h2>
<h2>jobs</h2>
<table>
<thead>
<th>Id</th>
<th>Worker Id</th>
<th>Job Id</th>
<th>Start time</th>
<th>Exited</th>
<th>Success</th>
</thead>
{{range $id, $jobs := .Jobs}}
{{range $_, $job := $jobs}}
<tr>
<td>{{$id}}</td>
<td>{{$job.StartTime}}</td>
<td>{{$job.Exited}}</td>
<td>{{$job.Success}}</td>
</tr>
{{end}}
{{range $jid, $job := $jobs}}
<tr>
<td>{{$id}}</td>
<td>{{$jid}}</td>
<td>{{$job.StartTime}}</td>
<td>{{$job.Exited}}</td>
<td>{{$job.Success}}</td>
</tr>
{{end}}
{{end}}
</table>
</body>

</html>
</html>
13 changes: 6 additions & 7 deletions cmd/ui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ type statusMap struct {

type jobsMap struct {
sync.RWMutex
// TODO: add job id by making the value a map.
jobs map[string][]*pb.JobResponse
jobs map[string]map[int64]*pb.JobResponse
}

func init() {
Expand All @@ -95,7 +94,7 @@ func init() {
status.Unlock()

jobs.Lock()
jobs.jobs = make(map[string][]*pb.JobResponse)
jobs.jobs = make(map[string]map[int64]*pb.JobResponse)
jobs.Unlock()
}

Expand All @@ -114,7 +113,7 @@ func Index(w http.ResponseWriter, req *http.Request) {

data := struct {
Status map[string]*pb.StatusResponse
Jobs map[string][]*pb.JobResponse
Jobs map[string]map[int64]*pb.JobResponse
}{status.status, jobs.jobs}

if err := indexTmpl.Execute(w, data); err != nil {
Expand Down Expand Up @@ -190,14 +189,14 @@ func updateWorkers(ctx context.Context) {
continue
}
glog.Infof("Jobs for %s: %+v", s.Id, jobsResp)
jrs := make([]*pb.JobResponse, len(jobsResp.Id))
for i, id := range jobsResp.Id {
jrs := make(map[int64]*pb.JobResponse)
for _, id := range jobsResp.Id {
j, err := s.Client.Job(ctx, &pb.JobRequest{Id: id})
if err != nil {
glog.Warningf("Failed to get job for %+v, %d: %s", s, id, err)
continue
}
jrs[i] = j
jrs[id] = j
}
jobs.Lock()
jobs.jobs[s.Id] = jrs
Expand Down

0 comments on commit af00448

Please sign in to comment.