Skip to content

Commit

Permalink
Moved int64arr to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Castell committed Dec 28, 2015
1 parent ea27dcc commit 3dd6001
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
25 changes: 3 additions & 22 deletions dkron/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"html/template"
"net/http"
"path/filepath"
"sort"

"github.com/gorilla/mux"
)
Expand All @@ -17,12 +16,6 @@ const (
apiPathPrefix = "v1"
)

type int64arr []int64

func (a int64arr) Len() int { return len(a) }
func (a int64arr) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a int64arr) Less(i, j int) bool { return a[i] < a[j] }

type commonDashboardData struct {
Version string
LeaderName string
Expand Down Expand Up @@ -141,18 +134,10 @@ func (a *AgentCommand) dashboardExecutionsHandler(w http.ResponseWriter, r *http
vars := mux.Vars(r)
job := vars["job"]

execs, _ := a.store.GetExecutions(job)
groups := make(map[int64][]*Execution)
for _, exec := range execs {
groups[exec.Group] = append(groups[exec.Group], exec)
}

// Build a separate data structure to show in order
var byGroup int64arr
for key := range groups {
byGroup = append(byGroup, key)
groups, byGroup, err := a.store.GetGroupedExecutions(job)
if err != nil {
log.Error(err)
}
sort.Sort(byGroup)

tmpl := template.Must(template.New("dashboard.html.tmpl").Funcs(template.FuncMap{
"html": func(value []byte) string {
Expand All @@ -171,10 +156,6 @@ func (a *AgentCommand) dashboardExecutionsHandler(w http.ResponseWriter, r *http
},
}).ParseFiles(templateSet(a.config.UIDir, "executions")...))

if len(execs) > 100 {
execs = execs[len(execs)-100:]
}

data := struct {
Common *commonDashboardData
Groups map[int64][]*Execution
Expand Down
6 changes: 6 additions & 0 deletions dkron/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ func generateSlug(str string) (slug string) {
return -1
}, strings.ToLower(strings.TrimSpace(str)))
}

type int64arr []int64

func (a int64arr) Len() int { return len(a) }
func (a int64arr) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a int64arr) Less(i, j int) bool { return a[i] < a[j] }

0 comments on commit 3dd6001

Please sign in to comment.