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): 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): Updated name of Local Metrics template
|
||||||
1. [14631](https://github.com/influxdata/influxdb/pull/14631): Dashboards for all Telegraf config bundles now created
|
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
|
### UI Improvements
|
||||||
|
|
||||||
|
|
|
@ -4206,6 +4206,11 @@ paths:
|
||||||
summary: List tasks.
|
summary: List tasks.
|
||||||
parameters:
|
parameters:
|
||||||
- $ref: '#/components/parameters/TraceSpan'
|
- $ref: '#/components/parameters/TraceSpan'
|
||||||
|
- in: query
|
||||||
|
name: name
|
||||||
|
description: only returns tasks with the specified name
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
- in: query
|
- in: query
|
||||||
name: after
|
name: after
|
||||||
schema:
|
schema:
|
||||||
|
|
|
@ -362,6 +362,10 @@ func decodeGetTasksRequest(ctx context.Context, r *http.Request, orgs platform.O
|
||||||
req.filter.Type = &ttype
|
req.filter.Type = &ttype
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if name := qp.Get("name"); name != "" {
|
||||||
|
req.filter.Name = &name
|
||||||
|
}
|
||||||
|
|
||||||
return req, nil
|
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 {
|
if filter.User != nil {
|
||||||
return s.findTasksByUser(ctx, tx, filter)
|
return s.findTasksByUser(ctx, tx, filter)
|
||||||
} else if org != nil {
|
} else if org != nil {
|
||||||
return s.findTaskByOrg(ctx, tx, filter)
|
return s.findTasksByOrg(ctx, tx, filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.findAllTasks(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
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if filter.Name != nil {
|
||||||
|
ts = filterByName(ts, *filter.Name)
|
||||||
|
}
|
||||||
|
|
||||||
return ts, len(ts), nil
|
return ts, len(ts), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// findTaskByOrg is a subset of the find tasks function. Used for cleanliness
|
// findTasksByOrg 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) {
|
func (s *Service) findTasksByOrg(ctx context.Context, tx Tx, filter influxdb.TaskFilter) ([]*influxdb.Task, int, error) {
|
||||||
var org *influxdb.Organization
|
var org *influxdb.Organization
|
||||||
var err error
|
var err error
|
||||||
if filter.OrganizationID != nil {
|
if filter.OrganizationID != nil {
|
||||||
|
@ -393,6 +398,11 @@ func (s *Service) findTaskByOrg(ctx context.Context, tx Tx, filter influxdb.Task
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if filter.Name != nil {
|
||||||
|
ts = filterByName(ts, *filter.Name)
|
||||||
|
}
|
||||||
|
|
||||||
return ts, len(ts), err
|
return ts, len(ts), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -475,9 +485,26 @@ func (s *Service) findAllTasks(ctx context.Context, tx Tx, filter influxdb.TaskF
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if filter.Name != nil {
|
||||||
|
ts = filterByName(ts, *filter.Name)
|
||||||
|
}
|
||||||
|
|
||||||
return ts, len(ts), err
|
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.
|
// CreateTask creates a new task.
|
||||||
// The owner of the task is inferred from the authorizer associated with ctx.
|
// 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) {
|
func (s *Service) CreateTask(ctx context.Context, tc influxdb.TaskCreate) (*influxdb.Task, error) {
|
||||||
|
|
1
task.go
1
task.go
|
@ -382,6 +382,7 @@ func (t *TaskUpdate) UpdateFlux(oldFlux string) error {
|
||||||
// TaskFilter represents a set of filters that restrict the returned results
|
// TaskFilter represents a set of filters that restrict the returned results
|
||||||
type TaskFilter struct {
|
type TaskFilter struct {
|
||||||
Type *string
|
Type *string
|
||||||
|
Name *string
|
||||||
After *ID
|
After *ID
|
||||||
OrganizationID *ID
|
OrganizationID *ID
|
||||||
Organization string
|
Organization string
|
||||||
|
|
Loading…
Reference in New Issue