Skip to content

Commit

Permalink
Add support for defining search attributes when updating schedules
Browse files Browse the repository at this point in the history
 - Added types search attribute field
 - more integration tests
  • Loading branch information
justinp-tt committed Jul 24, 2024
1 parent d681668 commit b0994bd
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 9 deletions.
13 changes: 10 additions & 3 deletions internal/internal_schedule_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func (scheduleHandle *scheduleHandleImpl) Update(ctx context.Context, options Sc
}

var newSA *commonpb.SearchAttributes
attributes := newSchedule.SearchAttributes
attributes := newSchedule.TypedSearchAttributes
if attributes != nil {
newSA, err = serializeTypedSearchAttributes(attributes.GetUntypedValues())
if err != nil {
Expand Down Expand Up @@ -495,6 +495,12 @@ func scheduleDescriptionFromPB(
return nil, err
}

var typedSearchAttributes SearchAttributes
searchAttributes := describeResponse.SearchAttributes
if searchAttributes != nil {
typedSearchAttributes = convertToTypedSearchAttributes(logger, searchAttributes.IndexedFields)
}

return &ScheduleDescription{
Schedule: Schedule{
Action: actionDescription,
Expand All @@ -521,8 +527,9 @@ func scheduleDescriptionFromPB(
CreatedAt: describeResponse.Info.GetCreateTime().AsTime(),
LastUpdateAt: describeResponse.Info.GetUpdateTime().AsTime(),
},
Memo: describeResponse.Memo,
SearchAttributes: describeResponse.SearchAttributes,
Memo: describeResponse.Memo,
SearchAttributes: searchAttributes,
TypedSearchAttributes: typedSearchAttributes,
}, nil
}

Expand Down
27 changes: 23 additions & 4 deletions internal/schedule_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,12 +416,31 @@ type (
// Memo - Non-indexed user supplied information.
Memo *commonpb.Memo

// SearchAttributes - Indexed info that can be used in query of List schedules APIs. The key and value type must be registered on Temporal server side.
// Use GetSearchAttributes API to get valid key and corresponding value type.
// SearchAttributes - Specifies Search Attributes that will be attached to the schedule. Search Attributes
// are additional indexed information attributed to the schedule and used for search and visibility. The key and
// its value type must be registered on Temporal server side.
// For supported operations on different server versions see [Visibility].
//
// nil: leave any pre-existing assigned search attributes intact
// empty: remove any and all pre-existing assigned search attributes
// attributes present: replace any and all pre-existing assigned search attributes with the defined search
// attributes, i.e. upsert
//
// [Visibility]: https://docs.temporal.io/visibility
SearchAttributes *commonpb.SearchAttributes

// TypedSearchAttributes - Specifies Search Attributes that will be attached to the schedule. Search Attributes
// are additional indexed information attributed to the schedule and used for search and visibility. The key and
// its value type must be registered on Temporal server side.
// For supported operations on different server versions see [Visibility].
//
// nil: leave any pre-existing assigned search attributes intact
// empty: remove any and all pre-existing assigned search attributes
// attributes present: replace any and all pre-existing assigned search attributes with the defined search
// attributes, i.e. upsert
//
// [Visibility]: https://docs.temporal.io/visibility
TypedSearchAttributes SearchAttributes
}

// SchedulePolicies describes the current polcies of a schedule.
Expand Down Expand Up @@ -477,9 +496,9 @@ type (
// Schedule - New schedule to replace the existing schedule with
Schedule *Schedule

// SearchAttributes - Optional indexed info that can be used for querying via the List schedules APIs.
// TypedSearchAttributes - Optional indexed info that can be used for querying via the List schedules APIs.
// The key and value type must be registered on Temporal server side.
SearchAttributes *SearchAttributes
TypedSearchAttributes *SearchAttributes
}

// ScheduleUpdateInput describes the current state of the schedule to be updated.
Expand Down
53 changes: 51 additions & 2 deletions test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4986,8 +4986,8 @@ func (ts *IntegrationTestSuite) TestScheduleUpdate() {

updateFunc := func(input client.ScheduleUpdateInput) (*client.ScheduleUpdate, error) {
return &client.ScheduleUpdate{
Schedule: &input.Description.Schedule,
SearchAttributes: &sa,
Schedule: &input.Description.Schedule,
TypedSearchAttributes: &sa,
}, nil
}
description, err := handle.Describe(ctx)
Expand All @@ -5002,8 +5002,57 @@ func (ts *IntegrationTestSuite) TestScheduleUpdate() {
description2, err := handle.Describe(ctx)
ts.NoError(err)
ts.Equal(description.Schedule, description2.Schedule)
ts.Equal(1, description2.TypedSearchAttributes.Size())
returnedSa, _ := description2.TypedSearchAttributes.GetString(stringKey)
expectedSa, _ := sa.GetString(stringKey)
ts.Equal(expectedSa, returnedSa)
return len(description2.SearchAttributes.IndexedFields) == 1
}, time.Second, 100*time.Millisecond)

// nil search attributes should leave current search attributes untouched
updateFunc = func(input client.ScheduleUpdateInput) (*client.ScheduleUpdate, error) {
return &client.ScheduleUpdate{
Schedule: &input.Description.Schedule,
}, nil
}

err = handle.Update(ctx, client.ScheduleUpdateOptions{
DoUpdate: updateFunc,
})
ts.NoError(err)

ts.Eventually(func() bool {
description2, err := handle.Describe(ctx)
ts.NoError(err)
ts.Equal(1, description2.TypedSearchAttributes.Size())
returnedSa, _ := description2.TypedSearchAttributes.GetString(stringKey)
expectedSa, _ := sa.GetString(stringKey)
ts.Equal(expectedSa, returnedSa)
return len(description2.SearchAttributes.IndexedFields) == 1
}, time.Second, 100*time.Millisecond)

// empty search attributes should remove pre-existing search attributes
sa = temporal.NewSearchAttributes()
updateFunc = func(input client.ScheduleUpdateInput) (*client.ScheduleUpdate, error) {
return &client.ScheduleUpdate{
Schedule: &input.Description.Schedule,
TypedSearchAttributes: &sa,
}, nil
}

err = handle.Update(ctx, client.ScheduleUpdateOptions{
DoUpdate: updateFunc,
})
ts.NoError(err)

ts.Eventually(func() bool {
description2, err := handle.Describe(ctx)
ts.NoError(err)
ts.Nil(description2.SearchAttributes)
ts.Empty(description2.TypedSearchAttributes)

return true
}, time.Second, 100*time.Millisecond)
}

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

0 comments on commit b0994bd

Please sign in to comment.