Skip to content

Commit

Permalink
separate out active from inactive jobs in the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
dmah42 committed Jun 1, 2022
1 parent 34fae40 commit 13ba5a5
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 17 deletions.
33 changes: 32 additions & 1 deletion cmd/ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,34 @@ <h2>status</h2>
</table>

<h2>jobs</h2>
<h3>active</h3>
{{$num_active_jobs := len .ActiveJobs}}
{{if ne $num_active_jobs 0}}
<table>
<thead>
<th>Worker Id</th>
<th>Job Id</th>
<th>State</th>
<th>Start time</th>
</thead>
{{range $id, $jobs := .ActiveJobs}}
{{range $jid, $job := $jobs}}
<tr>
<td>{{$id}}</td>
<td>{{$jid}}</td>
<td>{{$job.State}}</td>
<td>{{$job.StartTime}}</td>
</tr>
{{end}}
{{end}}
</table>
{{else}}
<p>no active jobs</p>
{{end}}

<h3>inactive</h3>
{{$num_inactive_jobs := len .InactiveJobs}}
{{if ne $num_inactive_jobs 0}}
<table>
<thead>
<th>Worker Id</th>
Expand All @@ -89,7 +117,7 @@ <h2>jobs</h2>
<th>Duration</th>
<th>Success</th>
</thead>
{{range $id, $jobs := .Jobs}}
{{range $id, $jobs := .InactiveJobs}}
{{range $jid, $job := $jobs}}
<tr>
<td>{{$id}}</td>
Expand All @@ -103,6 +131,9 @@ <h2>jobs</h2>
{{end}}
{{end}}
</table>
{{else}}
<p>No inactive jobs</p>
{{end}}
</body>

</html>
42 changes: 26 additions & 16 deletions cmd/ui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,12 @@ func (m *workerMap) add(s *internal.Worker) {
m.Unlock()
}

func (m *workerMap) remove(s *internal.Worker) error {
m.RLock()
defer m.RUnlock()
if _, ok := m.worker[s.Id]; !ok {
return fmt.Errorf("worker %q not found", s.Id)
}

func (m *workerMap) clear() {
m.Lock()
defer m.Unlock()
if _, ok := m.worker[s.Id]; !ok {
return fmt.Errorf("worker %q not found", s.Id)
for k := range m.worker {
delete(m.worker, k)
}
delete(m.worker, s.Id)

return nil
m.Unlock()
}

type statusMap struct {
Expand Down Expand Up @@ -118,9 +109,27 @@ func Index(w http.ResponseWriter, req *http.Request) {
defer jobs.RUnlock()

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

for id, js := range jobs.jobs {
data.ActiveJobs[id] = make(map[int64]*pb.JobResponse)
data.InactiveJobs[id] = make(map[int64]*pb.JobResponse)
for jid, job := range js {
switch job.State {
case pb.JobResponse_STATE_PENDING, pb.JobResponse_STATE_RUNNING:
data.ActiveJobs[id][jid] = job
case pb.JobResponse_STATE_UNKNOWN, pb.JobResponse_STATE_COMPLETE:
data.InactiveJobs[id][jid] = job
}
}
}

if err := indexTmpl.Execute(w, data); err != nil {
handleError(w, http.StatusInternalServerError, err)
Expand All @@ -129,6 +138,7 @@ func Index(w http.ResponseWriter, req *http.Request) {
}

func handleDiscoveryAcks(ctx context.Context, addrs <-chan string) {
worker.clear()
for saddr := range addrs {
glog.Infof("Discovered worker at %s", saddr)

Expand Down

0 comments on commit 13ba5a5

Please sign in to comment.