Skip to content

Commit

Permalink
feat(tasks): sort runs by most recently scheduled
Browse files Browse the repository at this point in the history
  • Loading branch information
AlirieGray committed Aug 8, 2019
1 parent 62d1474 commit 0cae89d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Features
1. [14495](https://github.com/influxdata/influxdb/pull/14495): optional gzip compression of the query CSV response.
1. [14567](https://github.com/influxdata/influxdb/pull/14567): Add task types.
1. [14604](https://github.com/influxdata/influxdb/pull/14604): When getting task runs from the API, runs will be returned in order of most recently scheduled first.

### UI Improvements

Expand Down
13 changes: 13 additions & 0 deletions http/task_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"
"net/url"
"path"
"sort"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -736,6 +737,16 @@ func decodeGetLogsRequest(ctx context.Context, r *http.Request) (*getLogsRequest
return req, nil
}

type runsBySchedule []*influxdb.Run

func (r runsBySchedule) Len() int { return len(r) }
func (r runsBySchedule) Less(i, j int) bool {
timeI, _ := r[i].ScheduledForTime()
timeJ, _ := r[j].ScheduledForTime()
return timeJ.Before(timeI)
}
func (r runsBySchedule) Swap(i, j int) { r[i], r[j] = r[j], r[i] }

func (h *TaskHandler) handleGetRuns(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

Expand Down Expand Up @@ -786,6 +797,8 @@ func (h *TaskHandler) handleGetRuns(w http.ResponseWriter, r *http.Request) {
return
}

sort.Sort(runsBySchedule(runs))

if err := encodeResponse(ctx, w, http.StatusOK, newRunsResponse(runs, req.filter.Task)); err != nil {
logEncodingError(h.logger, r, err)
return
Expand Down
3 changes: 2 additions & 1 deletion task/backend/analytical_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ func (as *AnalyticalStorage) FindRuns(ctx context.Context, filter influxdb.RunFi
%s
|> group(columns: ["taskID"])
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
|> limit(n:%d) // not for this PR
`, filter.Task.String(), filterPart)
`, filter.Task.String(), filterPart, filter.Limit-len(runs)) // not for this PR

// At this point we are behind authorization
// so we are faking a read only permission to the org's system bucket
Expand Down

0 comments on commit 0cae89d

Please sign in to comment.