Skip to content

Commit

Permalink
Add support for query parameter when listing schedules (#1556)
Browse files Browse the repository at this point in the history
* Add support for query parameter when listing schedules

* Add support for query parameter when listing schedules

Guard for eventual consistency
  • Loading branch information
justinp-tt authored Jul 22, 2024
1 parent 73bd320 commit 1350fb4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions internal/internal_schedule_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ func (sc *scheduleClient) List(ctx context.Context, options ScheduleListOptions)
Namespace: sc.workflowClient.namespace,
MaximumPageSize: int32(options.PageSize),
NextPageToken: nextToken,
Query: options.Query,
}

return sc.workflowClient.workflowService.ListSchedules(grpcCtx, request)
Expand Down
4 changes: 4 additions & 0 deletions internal/schedule_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,10 @@ type (
// PageSize - How many results to fetch from the Server at a time.
// Optional: defaulted to 1000
PageSize int

// Query - Filter results using a SQL-like query.
// Optional
Query string
}

// ScheduleListIterator represents the interface for
Expand Down
34 changes: 32 additions & 2 deletions test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4896,13 +4896,19 @@ func (ts *IntegrationTestSuite) TestScheduleBackfill() {
func (ts *IntegrationTestSuite) TestScheduleList() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

stringKey := temporal.NewSearchAttributeKeyKeyword("CustomKeywordField")

for i := 0; i < 5; i++ {
scheduleID := fmt.Sprintf("test-schedule-list-schedule-%d", i)
workflowID := fmt.Sprintf("test-schedule-list-workflow-%d", i)
attrId := stringKey.ValueSet(fmt.Sprintf("TestScheduleList-%d", i))

// Create a paused workflow
handle, err := ts.client.ScheduleClient().Create(ctx, client.ScheduleOptions{
ID: scheduleID,
Spec: client.ScheduleSpec{},
ID: scheduleID,
Spec: client.ScheduleSpec{},
TypedSearchAttributes: temporal.NewSearchAttributes(attrId),
Action: &client.ScheduleWorkflowAction{
Workflow: ts.workflows.SimplestWorkflow,
ID: workflowID,
Expand All @@ -4928,6 +4934,30 @@ func (ts *IntegrationTestSuite) TestScheduleList() {
}
ts.GreaterOrEqual(5, len(events))
ts.NoError(err)

// query -- match
ts.Eventually(func() bool {
iter, err = ts.client.ScheduleClient().List(ctx, client.ScheduleListOptions{
PageSize: 1,
Query: "CustomKeywordField = 'TestScheduleList-1'",
})
ts.NoError(err)
count := 0
for iter.HasNext() {
_, err = iter.Next()
ts.Nil(err)
count++
}
return count == 1
}, 10*time.Second, 100*time.Millisecond)

// query -- no match
iter, err = ts.client.ScheduleClient().List(ctx, client.ScheduleListOptions{
PageSize: 1,
Query: "CustomKeywordField = 'TestScheduleList-DOES_NOT_EXIST'",
})
ts.NoError(err)
ts.False(iter.HasNext())
}

func (ts *IntegrationTestSuite) TestScheduleUpdate() {
Expand Down

0 comments on commit 1350fb4

Please sign in to comment.