Skip to content

Commit

Permalink
Add execution filter to tasklist tasks CLI command (#462)
Browse files Browse the repository at this point in the history
* Add execution filter to tasklist tasks CLI command
  • Loading branch information
feedmeapples committed Jun 25, 2020
1 parent 679c91e commit 955587f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 18 deletions.
5 changes: 3 additions & 2 deletions tools/cli/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func newAdminShardManagementCommands() []cli.Command {
Usage: "List tasks for given shard Id and task type",
Flags: append(append(
getDBFlags(),
getFlagsForList()...),
flagsForPagination...),
cli.StringFlag{
Name: FlagTargetCluster,
Value: "active",
Expand Down Expand Up @@ -756,7 +756,8 @@ func newAdminTaskListCommands() []cli.Command {
{
Name: "list_tasks",
Usage: "List tasks of a tasklist",
Flags: append(getDBFlags(),
Flags: append(append(append(getDBFlags(), flagsForExecution...),
flagsForPagination...),
cli.StringFlag{
Name: FlagNamespaceID,
Usage: "Namespace Id",
Expand Down
36 changes: 32 additions & 4 deletions tools/cli/adminTaskListCommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ func AdminListTaskListTasks(c *cli.Context) {
}
minReadLvl := getRequiredInt64Option(c, FlagMinReadLevel)
maxReadLvl := getRequiredInt64Option(c, FlagMaxReadLevel)
workflowID := c.String(FlagWorkflowID)
runID := c.String(FlagRunID)

pFactory := CreatePersistenceFactory(c)
taskManager, err := pFactory.NewTaskManager()
Expand All @@ -135,9 +137,35 @@ func AdminListTaskListTasks(c *cli.Context) {
}

req := &persistence.GetTasksRequest{NamespaceID: namespace, TaskList: tlName, TaskType: tlType, ReadLevel: minReadLvl, MaxReadLevel: &maxReadLvl}
tasks, err := taskManager.GetTasks(req)
if err != nil {
ErrorAndExit("Failed to get Tasks", err)
paginationFunc := func(paginationToken []byte) ([]interface{}, []byte, error) {
response, err := taskManager.GetTasks(req)
if err != nil {
return nil, nil, err
}

tasks := response.Tasks
if workflowID != "" {
filteredTasks := tasks[:0]

for _, task := range tasks {
if task.Data.WorkflowId != workflowID {
continue
}
if runID != "" && task.Data.RunId != runID {
continue
}
filteredTasks = append(filteredTasks, task)
}

tasks = filteredTasks
}

var items []interface{}
for _, task := range tasks {
items = append(items, task)
}
return items, nil, nil
}
prettyPrintJSONObject(tasks)

paginate(c, paginationFunc)
}
25 changes: 13 additions & 12 deletions tools/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,18 @@ var flagsForExecution = []cli.Flag{
},
}

var flagsForPagination = []cli.Flag{
cli.BoolFlag{
Name: FlagMoreWithAlias,
Usage: "List more pages, default is to list one page of default page size 10",
},
cli.IntFlag{
Name: FlagPageSizeWithAlias,
Value: 10,
Usage: "Result page size",
},
}

func getFlagsForShow() []cli.Flag {
return append(flagsForExecution, getFlagsForShowID()...)
}
Expand Down Expand Up @@ -405,18 +417,7 @@ func getCommonFlagsForVisibility() []cli.Flag {
}

func getFlagsForList() []cli.Flag {
flagsForList := []cli.Flag{
cli.BoolFlag{
Name: FlagMoreWithAlias,
Usage: "List more pages, default is to list one page of default page size 10",
},
cli.IntFlag{
Name: FlagPageSizeWithAlias,
Value: 10,
Usage: "Result page size",
},
}
flagsForList = append(getFlagsForListAll(), flagsForList...)
flagsForList := append(getFlagsForListAll(), flagsForPagination...)
return flagsForList
}

Expand Down

0 comments on commit 955587f

Please sign in to comment.