Skip to content

Commit

Permalink
List schedules query param support (#654)
Browse files Browse the repository at this point in the history
<!--- Note to EXTERNAL Contributors -->
<!-- Thanks for opening a PR! 
If it is a significant code change, please **make sure there is an open
issue** for this.
We work best with you when we have accepted the idea first before you
code. -->

<!--- For ALL Contributors 👇 -->

## What was changed
<!-- Describe what has changed in this PR -->
Support for schedule list query parameter

## Why?
<!-- Tell your future self why have you made these changes -->

## Checklist
<!--- add/delete as needed --->

1. Closes <!-- add issue number here -->
#616

2. How was this tested:
<!--- Please describe how you tested your changes/how we can test them
-->
Added new tests

3. Any docs updates needed?
<!--- update README if applicable
      or point out where to update docs.temporal.io -->
  • Loading branch information
justinp-tt authored Sep 5, 2024
1 parent 32469e0 commit 5d2908a
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 15 deletions.
2 changes: 2 additions & 0 deletions temporalcli/commands.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,7 @@ type TemporalScheduleListCommand struct {
Command cobra.Command
Long bool
ReallyLong bool
Query string
}

func NewTemporalScheduleListCommand(cctx *CommandContext, parent *TemporalScheduleCommand) *TemporalScheduleListCommand {
Expand All @@ -1320,6 +1321,7 @@ func NewTemporalScheduleListCommand(cctx *CommandContext, parent *TemporalSchedu
s.Command.Args = cobra.NoArgs
s.Command.Flags().BoolVarP(&s.Long, "long", "l", false, "Include detailed information.")
s.Command.Flags().BoolVar(&s.ReallyLong, "really-long", false, "Include even more detailed information that's not really usable in table form.")
s.Command.Flags().StringVarP(&s.Query, "query", "q", "", "Filter results using given List Filter.")
s.Command.Run = func(c *cobra.Command, args []string) {
if err := s.run(cctx, args); err != nil {
cctx.Options.Fail(err)
Expand Down
8 changes: 6 additions & 2 deletions temporalcli/commands.schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import (
"time"

"github.com/temporalio/cli/temporalcli/internal/printer"
"google.golang.org/protobuf/encoding/protojson"

commonpb "go.temporal.io/api/common/v1"
enumspb "go.temporal.io/api/enums/v1"
schedpb "go.temporal.io/api/schedule/v1"
"go.temporal.io/api/workflowservice/v1"
"go.temporal.io/sdk/client"
"go.temporal.io/sdk/converter"
"go.temporal.io/server/common/primitives/timestamp"
"google.golang.org/protobuf/encoding/protojson"
)

type printableSchedule struct {
Expand Down Expand Up @@ -378,6 +379,7 @@ func (c *TemporalScheduleListCommand) run(cctx *CommandContext, args []string) e
res, err := cl.WorkflowService().ListSchedules(cctx, &workflowservice.ListSchedulesRequest{
Namespace: c.Parent.Namespace,
NextPageToken: token,
Query: c.Query,
})
if err != nil {
return err
Expand All @@ -397,7 +399,9 @@ func (c *TemporalScheduleListCommand) run(cctx *CommandContext, args []string) e
return nil
}

res, err := cl.ScheduleClient().List(cctx, client.ScheduleListOptions{})
res, err := cl.ScheduleClient().List(cctx, client.ScheduleListOptions{
Query: c.Query,
})
if err != nil {
return err
}
Expand Down
117 changes: 104 additions & 13 deletions temporalcli/commands.schedule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import (
"regexp"
"time"

"github.com/stretchr/testify/assert"
"github.com/temporalio/cli/temporalcli"

"go.temporal.io/api/enums/v1"
"go.temporal.io/api/operatorservice/v1"
"go.temporal.io/sdk/workflow"
)

Expand Down Expand Up @@ -173,42 +177,66 @@ func (s *SharedServerSuite) TestSchedule_CreateDescribe_SearchAttributes_Memo()
}

func (s *SharedServerSuite) TestSchedule_List() {
schedId, _, res := s.createSchedule("--interval", "10d")
res := s.Execute(
"operator", "search-attribute", "create",
"--address", s.Address(),
"--name", "TestSchedule_List",
"--type", "keyword",
)
s.NoError(res.Err)

// table

s.Eventually(func() bool {
s.EventuallyWithT(func(t *assert.CollectT) {
res = s.Execute(
"schedule", "list",
"operator", "search-attribute", "list",
"--address", s.Address(),
"-o", "json",
)
s.NoError(res.Err)
out := res.Stdout.String()
return AssertContainsOnSameLine(out, schedId, "DevWorkflow", "false") == nil
assert.NoError(t, res.Err)
var jsonOut operatorservice.ListSearchAttributesResponse
assert.NoError(t, temporalcli.UnmarshalProtoJSONWithOptions(res.Stdout.Bytes(), &jsonOut, true))
assert.Equal(t, enums.INDEXED_VALUE_TYPE_KEYWORD, jsonOut.CustomAttributes["TestSchedule_List"])
}, 10*time.Second, time.Second)

// table long
schedId, _, res := s.createSchedule(
"--interval",
"10d",
"--schedule-search-attribute", `TestSchedule_List="here"`,
)
s.NoError(res.Err)

// table really-long

res = s.Execute(
"schedule", "list",
"--address", s.Address(),
"--long",
"--really-long",
)
s.NoError(res.Err)
out := res.Stdout.String()
s.ContainsOnSameLine(out, schedId, "DevWorkflow", "0s" /*jitter*/, "false", "nil" /*memo*/)
s.ContainsOnSameLine(out, "TestSchedule_List")

// table

res = s.Execute(
"schedule", "list",
"--address", s.Address(),
)
s.NoError(res.Err)
out = res.Stdout.String()

s.ContainsOnSameLine(out, schedId, "DevWorkflow", "false")

// table really-long
// table long

res = s.Execute(
"schedule", "list",
"--address", s.Address(),
"--really-long",
"--long",
)
s.NoError(res.Err)
out = res.Stdout.String()
s.ContainsOnSameLine(out, schedId, "DevWorkflow", "0s" /*jitter*/, "false", "nil" /*memo*/)
s.ContainsOnSameLine(out, schedId, "DevWorkflow", "false")

// json

Expand Down Expand Up @@ -249,6 +277,69 @@ func (s *SharedServerSuite) TestSchedule_List() {
ok = ok || j.ScheduleId == schedId
}
s.True(ok, "schedule not found in jsonl result")

// JSON query (match)

res = s.Execute(
"schedule", "list",
"--address", s.Address(),
"--query", "TestSchedule_List = 'here'",
"-o", "json",
)
s.NoError(res.Err)
s.NoError(json.Unmarshal(res.Stdout.Bytes(), &j))
ok = false
for _, entry := range j {
ok = ok || entry.ScheduleId == schedId
}
s.True(ok, "schedule not found in json result")

// query (match)

res = s.Execute(
"schedule", "list",
"--address", s.Address(),
"--query", "TestSchedule_List = 'here'",
)
s.NoError(res.Err)
out = res.Stdout.String()
s.ContainsOnSameLine(out, schedId, "DevWorkflow", "false")

// JSON query (no matches)

res = s.Execute(
"schedule", "list",
"--address", s.Address(),
"--query", "TestSchedule_List = 'notHere'",
"-o", "json",
)
s.NoError(res.Err)
s.NoError(json.Unmarshal(res.Stdout.Bytes(), &j))
ok = false
for _, entry := range j {
ok = ok || entry.ScheduleId == schedId
}
s.False(ok, "schedule found in json result, but should not be found")

// query (no matches)

res = s.Execute(
"schedule", "list",
"--address", s.Address(),
"--query", "TestSchedule_List = 'notHere'",
)
s.NoError(res.Err)
out = res.Stdout.String()
s.NotContainsf(out, schedId, "schedule found, but should not be found")

// query (invalid query field)

res = s.Execute(
"schedule", "list",
"--address", s.Address(),
"--query", "unknownField = 'notHere'",
)
s.Error(res.Err)
}

func (s *SharedServerSuite) TestSchedule_Toggle() {
Expand Down
1 change: 1 addition & 0 deletions temporalcli/commandsmd/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ The `temporal schedule list` command lists all Schedules in a namespace.

* `--long`, `-l` (bool) - Include detailed information.
* `--really-long` (bool) - Include even more detailed information that's not really usable in table form.
* `--query`, `-q` (string) - Filter results using given List Filter.

### temporal schedule toggle: Pauses or unpauses a Schedule.

Expand Down

0 comments on commit 5d2908a

Please sign in to comment.