Skip to content

Commit

Permalink
Specify pagesize for workflow list command
Browse files Browse the repository at this point in the history
  • Loading branch information
yiminc committed Feb 7, 2025
1 parent de6f1c7 commit 9504ce3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
9 changes: 5 additions & 4 deletions temporalcli/commands.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
package temporalcli

import (
"os"
"time"

"github.com/mattn/go-isatty"

"github.com/spf13/cobra"

"github.com/spf13/pflag"

"os"

"time"
)

var hasHighlighting = isatty.IsTerminal(os.Stdout.Fd())
Expand Down Expand Up @@ -2896,6 +2895,7 @@ type TemporalWorkflowListCommand struct {
Query string
Archived bool
Limit int
Pagesize int
}

func NewTemporalWorkflowListCommand(cctx *CommandContext, parent *TemporalWorkflowCommand) *TemporalWorkflowListCommand {
Expand All @@ -2913,6 +2913,7 @@ func NewTemporalWorkflowListCommand(cctx *CommandContext, parent *TemporalWorkfl
s.Command.Flags().StringVarP(&s.Query, "query", "q", "", "Content for an SQL-like `QUERY` List Filter.")
s.Command.Flags().BoolVar(&s.Archived, "archived", false, "Limit output to archived Workflow Executions.")
s.Command.Flags().IntVar(&s.Limit, "limit", 0, "Maximum number of Workflow Executions to display.")
s.Command.Flags().IntVar(&s.Pagesize, "pagesize", 0, "Maximum number of Workflow Executions to return from server per request. Used for pagination.")
s.Command.Run = func(c *cobra.Command, args []string) {
if err := s.run(cctx, args); err != nil {
cctx.Options.Fail(err)
Expand Down
10 changes: 7 additions & 3 deletions temporalcli/commands.workflow_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,7 @@ func (c *TemporalWorkflowListCommand) run(cctx *CommandContext, _ []string) erro
cctx.Printer.StartList()
defer cctx.Printer.EndList()

// Build request and start looping. We always use default page size regardless
// of user-defined limit, because we're ok w/ extra page data and the default
// is not clearly defined.
// Build request and start looping.
pageFetcher := c.pageFetcher(cctx, cl)
var nextPageToken []byte
var execsProcessed int
Expand Down Expand Up @@ -360,16 +358,22 @@ func (c *TemporalWorkflowListCommand) pageFetcher(
cctx *CommandContext,
cl client.Client,
) func(next []byte) (workflowPage, error) {

if c.Limit > 0 && c.Limit < c.Pagesize {
c.Pagesize = c.Limit
}
return func(next []byte) (workflowPage, error) {
if c.Archived {
return cl.ListArchivedWorkflow(cctx, &workflowservice.ListArchivedWorkflowExecutionsRequest{
Query: c.Query,
NextPageToken: next,
PageSize: int32(c.Pagesize),
})
}
return cl.ListWorkflow(cctx, &workflowservice.ListWorkflowExecutionsRequest{
Query: c.Query,
NextPageToken: next,
PageSize: int32(c.Pagesize),
})
}
}
Expand Down
2 changes: 2 additions & 0 deletions temporalcli/commands.workflow_view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,12 @@ func (s *SharedServerSuite) TestWorkflow_List() {
"workflow", "list",
"--address", s.Address(),
"--query", fmt.Sprintf(`TaskQueue="%s"`, s.Worker().Options.TaskQueue),
"--pagesize", "1",
)
s.NoError(res.Err)
out := res.Stdout.String()
s.ContainsOnSameLine(out, "Completed", "DevWorkflow")
s.Equal(3, strings.Count(out, "DevWorkflow"))

// JSON
res = s.Execute(
Expand Down
3 changes: 3 additions & 0 deletions temporalcli/commandsgen/commands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2886,6 +2886,9 @@ commands:
- name: limit
type: int
description: Maximum number of Workflow Executions to display.
- name: pagesize
type: int
description: Maximum number of Workflow Executions to return from server per request. Used for pagination.

- name: temporal workflow metadata
summary: Query the Workflow for user-specified metadata
Expand Down

0 comments on commit 9504ce3

Please # to comment.