Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
view: Use the build_info time to sort jobs
Browse files Browse the repository at this point in the history
Fixes #42.
  • Loading branch information
apostergiou committed Apr 23, 2018
1 parent 2a572bc commit f85d068
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions cmd/mistryd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,26 +166,40 @@ func (s *Server) HandleIndex(w http.ResponseWriter, r *http.Request) {
}

for _, j := range pendingJobs {
bi := types.BuildInfo{}
biBlob, err := ioutil.ReadFile(filepath.Join(pendingPath, j.Name(), BuildInfoFname))
if err != nil {
s.Log.Printf("cannot read build_info file of job %s; %s", j.Name(), err)
w.WriteHeader(http.StatusInternalServerError)
return
}
err = json.Unmarshal(biBlob, &bi)
jobs = append(jobs, Job{
ID: j.Name(),
Project: p.Name(),
StartedAt: j.ModTime(),
Output: filepath.Join(pendingPath, j.Name(), BuildLogFname),
StartedAt: bi.StartedAt,
State: "pending"})
}

for _, j := range readyJobs {
bi := types.BuildInfo{}
biBlob, err := ioutil.ReadFile(filepath.Join(readyPath, j.Name(), BuildInfoFname))
if err != nil {
s.Log.Printf("cannot read build_info file of job %s; %s", j.Name(), err)
w.WriteHeader(http.StatusInternalServerError)
return
}
err = json.Unmarshal(biBlob, &bi)
jobs = append(jobs, Job{
ID: j.Name(),
Project: p.Name(),
StartedAt: j.ModTime(),
Output: filepath.Join(readyPath, j.Name(), BuildLogFname),
StartedAt: bi.StartedAt,
State: "ready"})
}
}

sort.Slice(jobs, func(i, j int) bool {
return jobs[i].StartedAt.Unix() > jobs[j].StartedAt.Unix()
return jobs[j].StartedAt.Before(jobs[i].StartedAt)
})

resp, err := json.Marshal(jobs)
Expand Down

0 comments on commit f85d068

Please sign in to comment.