From 13ba5a56bc07b6f77e5f6dcd5fc6f412badd2ab9 Mon Sep 17 00:00:00 2001 From: Dominic Hamon Date: Wed, 1 Jun 2022 21:26:26 +0100 Subject: [PATCH] separate out active from inactive jobs in the UI --- cmd/ui/index.html | 33 ++++++++++++++++++++++++++++++++- cmd/ui/main.go | 42 ++++++++++++++++++++++++++---------------- 2 files changed, 58 insertions(+), 17 deletions(-) diff --git a/cmd/ui/index.html b/cmd/ui/index.html index 6da20d7..2f7c67b 100644 --- a/cmd/ui/index.html +++ b/cmd/ui/index.html @@ -79,6 +79,34 @@

status

jobs

+

active

+ {{$num_active_jobs := len .ActiveJobs}} + {{if ne $num_active_jobs 0}} + + + + + + + + {{range $id, $jobs := .ActiveJobs}} + {{range $jid, $job := $jobs}} + + + + + + + {{end}} + {{end}} +
Worker IdJob IdStateStart time
{{$id}}{{$jid}}{{$job.State}}{{$job.StartTime}}
+ {{else}} +

no active jobs

+ {{end}} + +

inactive

+ {{$num_inactive_jobs := len .InactiveJobs}} + {{if ne $num_inactive_jobs 0}} @@ -89,7 +117,7 @@

jobs

- {{range $id, $jobs := .Jobs}} + {{range $id, $jobs := .InactiveJobs}} {{range $jid, $job := $jobs}} @@ -103,6 +131,9 @@

jobs

{{end}} {{end}}
Worker Id Duration Success
{{$id}}
+ {{else}} +

No inactive jobs

+ {{end}} \ No newline at end of file diff --git a/cmd/ui/main.go b/cmd/ui/main.go index 99f7793..ea71f10 100644 --- a/cmd/ui/main.go +++ b/cmd/ui/main.go @@ -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 { @@ -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) @@ -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)