Skip to content

Commit

Permalink
feat(tasks): add ability to find tasks by name
Browse files Browse the repository at this point in the history
  • Loading branch information
AlirieGray committed Aug 16, 2019
1 parent 1f499d5 commit bf5a6b4
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
1. [14631](https://github.com/influxdata/influxdb/pull/14631): Added Github and Apache templates
1. [14631](https://github.com/influxdata/influxdb/pull/14631): Updated name of Local Metrics template
1. [14631](https://github.com/influxdata/influxdb/pull/14631): Dashboards for all Telegraf config bundles now created
1. [14694](https://github.com/influxdata/influxdb/pull/14694): Add ability to find tasks by name.

### UI Improvements

Expand Down
5 changes: 5 additions & 0 deletions http/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4206,6 +4206,11 @@ paths:
summary: List tasks.
parameters:
- $ref: '#/components/parameters/TraceSpan'
- in: query
name: name
description: only returns tasks with the specified name
schema:
type: string
- in: query
name: after
schema:
Expand Down
4 changes: 4 additions & 0 deletions http/task_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ func decodeGetTasksRequest(ctx context.Context, r *http.Request, orgs platform.O
req.filter.Type = &ttype
}

if name := qp.Get("name"); name != "" {
req.filter.Name = &name
}

return req, nil
}

Expand Down
33 changes: 30 additions & 3 deletions kv/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (s *Service) findTasks(ctx context.Context, tx Tx, filter influxdb.TaskFilt
if filter.User != nil {
return s.findTasksByUser(ctx, tx, filter)
} else if org != nil {
return s.findTaskByOrg(ctx, tx, filter)
return s.findTasksByOrg(ctx, tx, filter)
}

return s.findAllTasks(ctx, tx, filter)
Expand Down Expand Up @@ -270,11 +270,16 @@ func (s *Service) findTasksByUser(ctx context.Context, tx Tx, filter influxdb.Ta
break
}
}

if filter.Name != nil {
ts = filterByName(ts, *filter.Name)
}

return ts, len(ts), nil
}

// findTaskByOrg is a subset of the find tasks function. Used for cleanliness
func (s *Service) findTaskByOrg(ctx context.Context, tx Tx, filter influxdb.TaskFilter) ([]*influxdb.Task, int, error) {
// findTasksByOrg is a subset of the find tasks function. Used for cleanliness
func (s *Service) findTasksByOrg(ctx context.Context, tx Tx, filter influxdb.TaskFilter) ([]*influxdb.Task, int, error) {
var org *influxdb.Organization
var err error
if filter.OrganizationID != nil {
Expand Down Expand Up @@ -393,6 +398,11 @@ func (s *Service) findTaskByOrg(ctx context.Context, tx Tx, filter influxdb.Task
break
}
}

if filter.Name != nil {
ts = filterByName(ts, *filter.Name)
}

return ts, len(ts), err
}

Expand Down Expand Up @@ -475,9 +485,26 @@ func (s *Service) findAllTasks(ctx context.Context, tx Tx, filter influxdb.TaskF
break
}
}

if filter.Name != nil {
ts = filterByName(ts, *filter.Name)
}

return ts, len(ts), err
}

func filterByName(ts []*influxdb.Task, taskName string) []*influxdb.Task {
filtered := []*influxdb.Task{}

for _, task := range ts {
if task.Name == taskName {
filtered = append(filtered, task)
}
}

return filtered
}

// CreateTask creates a new task.
// The owner of the task is inferred from the authorizer associated with ctx.
func (s *Service) CreateTask(ctx context.Context, tc influxdb.TaskCreate) (*influxdb.Task, error) {
Expand Down
1 change: 1 addition & 0 deletions task.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ func (t *TaskUpdate) UpdateFlux(oldFlux string) error {
// TaskFilter represents a set of filters that restrict the returned results
type TaskFilter struct {
Type *string
Name *string
After *ID
OrganizationID *ID
Organization string
Expand Down

0 comments on commit bf5a6b4

Please sign in to comment.