Skip to content

Commit

Permalink
Merge pull request #14604 from influxdata/tasks/sort-runs-by-time-sch…
Browse files Browse the repository at this point in the history
…eduled

feat(tasks): sort runs by most recently scheduled
  • Loading branch information
AlirieGray authored Aug 12, 2019
2 parents ee8dc2d + 16c400c commit 02765c6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
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
1 change: 1 addition & 0 deletions task/backend/analytical_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ func (as *AnalyticalStorage) FindRuns(ctx context.Context, filter influxdb.RunFi
|> group(columns: ["taskID"])
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
|> limit(n:%d)
|> sort(columns:["scheduledFor"], desc: true)
`, filter.Task.String(), filterPart, filter.Limit-len(runs))

Expand Down
19 changes: 10 additions & 9 deletions task/servicetest/servicetest.go
Original file line number Diff line number Diff line change
Expand Up @@ -1155,8 +1155,9 @@ func testRunStorage(t *testing.T, sys *System) {
t.Fatalf("retrieved wrong run ID; want %s, got %s", rc0.Created.RunID, runs[0].ID)
}

// Unspecified limit returns all three runs.
// Unspecified limit returns all three runs, sorted by most recently scheduled first.
runs, _, err = sys.TaskService.FindRuns(sys.Ctx, influxdb.RunFilter{Task: task.ID})

if err != nil {
t.Fatal(err)
}
Expand All @@ -1176,17 +1177,17 @@ func testRunStorage(t *testing.T, sys *System) {
t.Fatalf("expected empty FinishedAt, got %q", runs[0].FinishedAt)
}

if runs[1].ID != rc1.Created.RunID {
t.Fatalf("retrieved wrong run ID; want %s, got %s", rc1.Created.RunID, runs[1].ID)
if runs[2].ID != rc1.Created.RunID {
t.Fatalf("retrieved wrong run ID; want %s, got %s", rc2.Created.RunID, runs[1].ID)
}
if runs[1].StartedAt != startedAt.Add(time.Second).Format(time.RFC3339Nano) {
t.Fatalf("unexpected StartedAt; want %s, got %s", runs[0].StartedAt, startedAt.Add(time.Second))
if runs[2].StartedAt != startedAt.Add(time.Second).Format(time.RFC3339Nano) {
t.Fatalf("unexpected StartedAt; want %s, got %s", runs[1].StartedAt, startedAt.Add(time.Second))
}
if runs[1].Status != backend.RunSuccess.String() {
t.Fatalf("unexpected run status; want %s, got %s", backend.RunSuccess.String(), runs[0].Status)
if runs[2].Status != backend.RunSuccess.String() {
t.Fatalf("unexpected run status; want %s, got %s", backend.RunSuccess.String(), runs[2].Status)
}
if exp := startedAt.Add(time.Second * 2).Format(time.RFC3339Nano); runs[1].FinishedAt != exp {
t.Fatalf("unexpected FinishedAt; want %s, got %s", exp, runs[1].FinishedAt)
if exp := startedAt.Add(time.Second * 2).Format(time.RFC3339Nano); runs[2].FinishedAt != exp {
t.Fatalf("unexpected FinishedAt; want %s, got %s", exp, runs[2].FinishedAt)
}

// Look for a run that doesn't exist.
Expand Down

0 comments on commit 02765c6

Please sign in to comment.