feat(tasks): add ability to find tasks by name
parent
1f499d599a
commit
28089fdb59
|
@ -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
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
33
kv/task.go
33
kv/task.go
|
@ -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)
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue