Skip to content

Commit

Permalink
CLI: Add list workers of tasklist (uber#597)
Browse files Browse the repository at this point in the history
* Add CLI to homepage readme

* Add list worker info of tasklist

* Adjust import order
  • Loading branch information
vancexu authored Mar 8, 2018
1 parent 64327c5 commit 08652db
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ You can also [build and run](docker/README.md) the service using Docker.

Try out the sample recipes [here](https://github.com/samarabbas/cadence-samples) to get started.

### Use CLI

Try out [Cadence command-line tool](tools/cli/README.md) to perform various tasks on Cadence

## Contributing
We'd love your help in making Cadence great. Please review our [instructions](CONTRIBUTING.md).

Expand Down
7 changes: 7 additions & 0 deletions tools/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ also start workflow, show workflow history, signal workflow ... and many other t
Run `./cadence` to view help message. There are some top level commands and global options.
Run `./cadence domain` to view help message about operations on domain
Run `./cadence workflow` to view help message about operations on workflow
Run `./cadence tasklist` to view help message about operations on tasklist
(`./cadence help`, `./cadence help [domain|workflow]` will also print help messages)

**Note:** make sure you have cadence server running before using CLI
Expand Down Expand Up @@ -58,6 +59,12 @@ and it takes a string as input, so there is the `-i '"cadence"'`. Single quote `
**Note:** you need to start worker so that workflow can make progress.
(Run `make && ./bin/helloworld -m worker` in cadence-samples to start the worker)

- Show running workers of a tasklist
```
./cadence tasklist desc --tl helloWorldGroup
```

- Start workflow:
```
./cadence workflow start --tl helloWorldGroup --wt main.Workflow --et 60 -i '"cadence"'
Expand Down
6 changes: 6 additions & 0 deletions tools/cli/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ func NewCliApp() *cli.App {
Usage: "Operate cadence workflow",
Subcommands: newWorkflowCommands(),
},
{
Name: "tasklist",
Aliases: []string{"tl"},
Usage: "Operate cadence tasklist",
Subcommands: newTaskListCommands(),
},
}

// set builder if not customized
Expand Down
39 changes: 39 additions & 0 deletions tools/cli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"os"
"runtime/debug"
"strconv"
"strings"
"time"

"github.com/fatih/color"
Expand Down Expand Up @@ -59,6 +60,8 @@ const (
FlagRunIDWithAlias = FlagRunID + ", rid, r"
FlagTaskList = "tasklist"
FlagTaskListWithAlias = FlagTaskList + ", tl"
FlagTaskListType = "tasklisttype"
FlagTaskListTypeWithAlias = FlagTaskListType + ", tlt"
FlagWorkflowType = "workflow_type"
FlagWorkflowTypeWithAlias = FlagWorkflowType + ", wt"
FlagExecutionTimeout = "execution_timeout"
Expand Down Expand Up @@ -693,6 +696,35 @@ func listClosedWorkflow(client client.Client, pageSize int, earliestTime, latest
return response.Executions, response.NextPageToken
}

// DescribeTaskList show pollers info of a given tasklist
func DescribeTaskList(c *cli.Context) {
wfClient := getWorkflowClient(c)
taskList := getRequiredOption(c, FlagTaskList)
taskListType := strToTaskListType(c.String(FlagTaskListType)) // default type is decision

ctx, cancel := newContext()
defer cancel()
response, err := wfClient.DescribeTaskList(ctx, taskList, taskListType)
if err != nil {
ErrorAndExit("DescribeTaskList failed", err)
}

pollers := response.Pollers
if len(pollers) == 0 {
fmt.Println(colorMagenta("No poller for tasklist: " + taskList))
return
}

table := tablewriter.NewWriter(os.Stdout)
table.SetBorder(false)
table.SetColumnSeparator("|")
table.Append([]string{"Poller Identity", "Last Access Time"})
for _, poller := range pollers {
table.Append([]string{poller.GetIdentity(), convertTime(poller.GetLastAccessTime())})
}
table.Render()
}

func getDomainClient(c *cli.Context) client.DomainClient {
service, err := cBuilder.BuildServiceClient(c)
if err != nil {
Expand Down Expand Up @@ -772,6 +804,13 @@ func parseTime(timeStr string, defaultValue int64) int64 {
return resultValue
}

func strToTaskListType(str string) s.TaskListType {
if strings.ToLower(str) == "activity" {
return s.TaskListTypeActivity
}
return s.TaskListTypeDecision
}

func getPtrOrNilIfEmpty(value string) *string {
if value == "" {
return nil
Expand Down
47 changes: 47 additions & 0 deletions tools/cli/tasklist.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package cli

import "github.com/urfave/cli"

func newTaskListCommands() []cli.Command {
return []cli.Command{
{
Name: "describe",
Aliases: []string{"desc"},
Usage: "Describe pollers info of tasklist",
Flags: []cli.Flag{
cli.StringFlag{
Name: FlagTaskListWithAlias,
Usage: "TaskList description",
},
cli.StringFlag{
Name: FlagTaskListTypeWithAlias,
Value: "decision",
Usage: "Optional TaskList type [decision|activity]",
},
},
Action: func(c *cli.Context) {
DescribeTaskList(c)
},
},
}
}

0 comments on commit 08652db

Please sign in to comment.