diff --git a/cmd/influx/task.go b/cmd/influx/task.go index e5e88d5815..20893e2f09 100644 --- a/cmd/influx/task.go +++ b/cmd/influx/task.go @@ -173,6 +173,7 @@ type TaskFindFlags struct { user string id string orgID string + limit int } var taskFindFlags TaskFindFlags @@ -187,6 +188,7 @@ func init() { taskFindCmd.Flags().StringVarP(&taskFindFlags.id, "id", "i", "", "task ID") taskFindCmd.Flags().StringVarP(&taskFindFlags.user, "user-id", "n", "", "task owner ID") taskFindCmd.Flags().StringVarP(&taskFindFlags.orgID, "org-id", "", "", "task organization ID") + taskFindCmd.Flags().IntVarP(&taskFindFlags.limit, "limit", "", platform.TaskDefaultPageSize, "the number of tasks to find") taskCmd.AddCommand(taskFindCmd) } @@ -216,6 +218,12 @@ func taskFindF(cmd *cobra.Command, args []string) { filter.Organization = id } + if taskFindFlags.limit < 1 || taskFindFlags.limit > platform.TaskMaxPageSize { + fmt.Printf("limit must be between 1 and %d \n", platform.TaskMaxPageSize) + os.Exit(1) + } + filter.Limit = taskFindFlags.limit + var tasks []*platform.Task var err error diff --git a/http/task_service.go b/http/task_service.go index 2fa8a618e6..387c7f6b4b 100644 --- a/http/task_service.go +++ b/http/task_service.go @@ -225,6 +225,19 @@ func decodeGetTasksRequest(ctx context.Context, r *http.Request) (*getTasksReque req.filter.User = id } + if limit := qp.Get("limit"); limit != "" { + lim, err := strconv.Atoi(limit) + if err != nil { + return nil, err + } + if lim < 1 || lim > platform.TaskMaxPageSize { + return nil, kerrors.InvalidDataf("limit must be between 1 and %d", platform.TaskMaxPageSize) + } + req.filter.Limit = lim + } else { + req.filter.Limit = platform.TaskDefaultPageSize + } + return req, nil } @@ -809,6 +822,9 @@ func (t TaskService) FindTasks(ctx context.Context, filter platform.TaskFilter) if filter.User != nil { val.Add("user", filter.User.String()) } + if filter.Limit != 0 { + val.Add("limit", strconv.Itoa(filter.Limit)) + } u.RawQuery = val.Encode() diff --git a/task.go b/task.go index 681ea6182c..ce81e1f6a9 100644 --- a/task.go +++ b/task.go @@ -4,6 +4,11 @@ import ( "context" ) +const ( + TaskDefaultPageSize = 100 + TaskMaxPageSize = 500 +) + // Task is a task. 🎊 type Task struct { ID ID `json:"id,omitempty"` @@ -78,6 +83,7 @@ type TaskFilter struct { After *ID Organization *ID User *ID + Limit int } // RunFilter represents a set of filters that restrict the returned results diff --git a/task/platform_adapter.go b/task/platform_adapter.go index f6b51925c6..9816375f52 100644 --- a/task/platform_adapter.go +++ b/task/platform_adapter.go @@ -43,9 +43,7 @@ func (p pAdapter) FindTaskByID(ctx context.Context, id platform.ID) (*platform.T } func (p pAdapter) FindTasks(ctx context.Context, filter platform.TaskFilter) ([]*platform.Task, int, error) { - const pageSize = 100 // According to the platform.TaskService.FindTasks API. - - params := backend.TaskSearchParams{PageSize: pageSize} + params := backend.TaskSearchParams{PageSize: filter.Limit} if filter.Organization != nil { params.Org = *filter.Organization } @@ -68,8 +66,7 @@ func (p pAdapter) FindTasks(ctx context.Context, filter platform.TaskFilter) ([] } } - totalResults := len(pts) // TODO(mr): don't lie about the total results. Update ListTasks signature? - return pts, totalResults, nil + return pts, len(pts), nil } func (p pAdapter) CreateTask(ctx context.Context, t *platform.Task) error {