Skip to content

Commit

Permalink
fix job status and add job duration in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
dmah42 committed Jun 1, 2022
1 parent 25d8ef5 commit 34fae40
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
26 changes: 15 additions & 11 deletions cmd/ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,26 @@ <h2>jobs</h2>
<thead>
<th>Worker Id</th>
<th>Job Id</th>
<th>State</th>
<th>Start time</th>
<th>Exited</th>
<th>End time</th>
<th>Duration</th>
<th>Success</th>
</thead>
{{range $id, $jobs := .Jobs}}
{{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}}
{{range $jid, $job := $jobs}}
<tr>
<td>{{$id}}</td>
<td>{{$jid}}</td>
<td>{{$job.State}}</td>
<td>{{$job.StartTime}}</td>
<td>{{$job.EndTime}}</td>
<td>{{duration $job.StartTime $job.EndTime}}</td>
<td>{{$job.Success}}</td>
</tr>
{{end}}
{{end}}
</table>
</body>

</html>
</html>
6 changes: 6 additions & 0 deletions cmd/ui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ var (
"toGB": func(bytes uint64) string {
return fmt.Sprintf("%.3f", float64(bytes)/(1000*1000*1000))
},
"duration": func(start int64, end int64) time.Duration {
if end == 0 {
return 0
}
return time.Unix(end, 0).Sub(time.Unix(start, 0))
},
}
)

Expand Down
18 changes: 8 additions & 10 deletions cmd/worker/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,6 @@ func (s *workerServer) Run(_ context.Context, req *pb.RunRequest) (*pb.RunRespon
j := jobs.jobs[id]
jobs.RUnlock()

if err := j.cmd.Wait(); err != nil {
fmt.Println(err)
}

out, err := ioutil.ReadAll(stdout)
if err != nil {
glog.Error(err)
Expand All @@ -168,6 +164,10 @@ func (s *workerServer) Run(_ context.Context, req *pb.RunRequest) (*pb.RunRespon
j.stderr = string(out)
}

if err := j.cmd.Wait(); err != nil {
fmt.Println(err)
}

glog.Infof("Marking job %d as complete", id)
j.complete = true
j.end = time.Now()
Expand All @@ -189,15 +189,13 @@ func (s *workerServer) Job(_ context.Context, req *pb.JobRequest) (*pb.JobRespon
StartTime: job.start.Unix(),
State: pb.JobResponse_STATE_UNKNOWN,
}
// TODO: when jobs are queued: return pending here.
resp.State = pb.JobResponse_STATE_RUNNING
if job.cmd.ProcessState != nil {
resp.Success = job.cmd.ProcessState.Success()

if job.cmd.ProcessState.Exited() {
resp.EndTime = job.end.Unix()
resp.State = pb.JobResponse_STATE_COMPLETE
} else {
resp.State = pb.JobResponse_STATE_RUNNING
}
resp.EndTime = job.end.Unix()
resp.State = pb.JobResponse_STATE_COMPLETE

su := job.cmd.ProcessState.SysUsage().(*syscall.Rusage)
if su != nil {
Expand Down

0 comments on commit 34fae40

Please sign in to comment.