Skip to content

Commit

Permalink
Merge pull request #179 from rasputnik/sort_tasks_by_id_not_stagedat
Browse files Browse the repository at this point in the history
sort tasks by .Id, not .StagedAt. fixes #177
  • Loading branch information
lclarkmichalek committed Nov 12, 2015
2 parents f3f054f + 67f5347 commit b57de95
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions services/marathon/marathon.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (slice marathonTaskList) Len() int {
}

func (slice marathonTaskList) Less(i, j int) bool {
return slice[i].StagedAt < slice[j].StagedAt
return slice[i].Id < slice[j].Id
}

func (slice marathonTaskList) Swap(i, j int) {
Expand Down Expand Up @@ -136,7 +136,7 @@ func fetchMarathonApps(endpoint string, conf *configuration.Configuration) (map[
return dataById, nil
}

func fetchTasks(endpoint string, conf *configuration.Configuration) (map[string][]marathonTask, error) {
func fetchTasks(endpoint string, conf *configuration.Configuration) (map[string]marathonTaskList, error) {
client := &http.Client{}
req, _ := http.NewRequest("GET", endpoint+"/v2/tasks", nil)
req.Header.Add("Accept", "application/json")
Expand Down Expand Up @@ -166,18 +166,22 @@ func fetchTasks(endpoint string, conf *configuration.Configuration) (map[string]
taskList := tasks.Tasks
sort.Sort(taskList)

tasksById := map[string][]marathonTask{}
tasksById := map[string]marathonTaskList{}
for _, task := range taskList {
if tasksById[task.AppId] == nil {
tasksById[task.AppId] = []marathonTask{}
tasksById[task.AppId] = marathonTaskList{}
}
tasksById[task.AppId] = append(tasksById[task.AppId], task)
}

for _, task_list := range tasksById {
sort.Sort(task_list)
}

return tasksById, nil
}

func createApps(tasksById map[string][]marathonTask, marathonApps map[string]marathonApp) AppList {
func createApps(tasksById map[string]marathonTaskList, marathonApps map[string]marathonApp) AppList {

apps := AppList{}

Expand Down

0 comments on commit b57de95

Please sign in to comment.