Skip to content

Commit 24c5b5f

Browse files
committed
change functional Option pattern to internal.GetVersionOptions
1 parent b2c664f commit 24c5b5f

File tree

6 files changed

+26
-36
lines changed

6 files changed

+26
-36
lines changed

internal/interceptors.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type WorkflowInterceptor interface {
6363
GetSignalChannel(ctx Context, signalName string) Channel
6464
SideEffect(ctx Context, f func(ctx Context) interface{}) Value
6565
MutableSideEffect(ctx Context, id string, f func(ctx Context) interface{}, equals func(a, b interface{}) bool) Value
66-
GetVersion(ctx Context, changeID string, minSupported, maxSupported Version, opts ...GetVersionOption) Version
66+
GetVersion(ctx Context, changeID string, minSupported, maxSupported Version, opts ...GetVersionOptions) Version
6767
SetQueryHandler(ctx Context, queryType string, handler interface{}) error
6868
IsReplaying(ctx Context) bool
6969
HasLastCompletionResult(ctx Context) bool
@@ -158,7 +158,7 @@ func (t *WorkflowInterceptorBase) MutableSideEffect(ctx Context, id string, f fu
158158
}
159159

160160
// GetVersion forwards to t.Next
161-
func (t *WorkflowInterceptorBase) GetVersion(ctx Context, changeID string, minSupported, maxSupported Version, opts ...GetVersionOption) Version {
161+
func (t *WorkflowInterceptorBase) GetVersion(ctx Context, changeID string, minSupported, maxSupported Version, opts ...GetVersionOptions) Version {
162162
return t.Next.GetVersion(ctx, changeID, minSupported, maxSupported, opts...)
163163
}
164164

internal/internal_event_handlers.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ func validateVersion(changeID string, version, minSupported, maxSupported Versio
602602
}
603603
}
604604

605-
func (wc *workflowEnvironmentImpl) GetVersion(changeID string, minSupported, maxSupported Version, opts ...GetVersionOption) Version {
605+
func (wc *workflowEnvironmentImpl) GetVersion(changeID string, minSupported, maxSupported Version, opts ...GetVersionOptions) Version {
606606
// Check if the changeID already has a version assigned
607607
// If it does, validate the version against the min and max supported versions
608608
// ensuring it is within the acceptable range
@@ -611,10 +611,10 @@ func (wc *workflowEnvironmentImpl) GetVersion(changeID string, minSupported, max
611611
return version
612612
}
613613

614-
// Apply options to determine which version to use
615-
options := &GetVersionOptions{}
616-
for _, opt := range opts {
617-
opt(options)
614+
// Use the first option if they're present
615+
var options GetVersionOptions
616+
if len(opts) > 0 {
617+
options = opts[0]
618618
}
619619

620620
var version Version

internal/internal_worker_base.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ type (
7676
localActivityClient
7777
workflowTimerClient
7878
SideEffect(f func() ([]byte, error), callback resultHandler)
79-
GetVersion(changeID string, minSupported, maxSupported Version, opts ...GetVersionOption) Version
79+
GetVersion(changeID string, minSupported, maxSupported Version, opts ...GetVersionOptions) Version
8080
WorkflowInfo() *WorkflowInfo
8181
Complete(result []byte, err error)
8282
RegisterCancelHandler(handler func())

internal/internal_workflow_testsuite.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1928,7 +1928,7 @@ func (env *testWorkflowEnvironmentImpl) SideEffect(f func() ([]byte, error), cal
19281928
callback(f())
19291929
}
19301930

1931-
func (env *testWorkflowEnvironmentImpl) GetVersion(changeID string, minSupported, maxSupported Version, opts ...GetVersionOption) (retVersion Version) {
1931+
func (env *testWorkflowEnvironmentImpl) GetVersion(changeID string, minSupported, maxSupported Version, opts ...GetVersionOptions) (retVersion Version) {
19321932
if mockVersion, ok := env.getMockedVersion(changeID, changeID, minSupported, maxSupported); ok {
19331933
// GetVersion for changeID is mocked
19341934
env.UpsertSearchAttributes(createSearchAttributesForChangeVersion(changeID, mockVersion, env.changeVersions))

internal/workflow.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,9 +1567,6 @@ const DefaultVersion Version = -1
15671567
// CadenceChangeVersion is used as search attributes key to find workflows with specific change version.
15681568
const CadenceChangeVersion = "CadenceChangeVersion"
15691569

1570-
// GetVersionOption configures GetVersion behavior
1571-
type GetVersionOption func(*GetVersionOptions)
1572-
15731570
// GetVersionOptions contains options for GetVersion
15741571
type GetVersionOptions struct {
15751572
// CustomVersion is used to force GetVersion to return a specific version
@@ -1581,7 +1578,7 @@ type GetVersionOptions struct {
15811578
UseMinVersion bool
15821579
}
15831580

1584-
// ExecuteWithVersion returns a GetVersionOption that forces a specific version to be returned
1581+
// ExecuteWithVersion returns a GetVersionOptions that forces a specific version to be returned
15851582
// when executed for the first time, instead of returning maxSupported version.
15861583
//
15871584
// This option can be used when you want to separate the versioning of the workflow code and
@@ -1637,18 +1634,18 @@ type GetVersionOptions struct {
16371634
//
16381635
// ExecuteWithVersion option is useful when you want to ensure that your changes can be safely rolled back if needed, as
16391636
// both versions of the workflow code are compatible with each other.
1640-
func ExecuteWithVersion(version Version) GetVersionOption {
1641-
return func(o *GetVersionOptions) {
1642-
o.CustomVersion = &version
1637+
func ExecuteWithVersion(version Version) GetVersionOptions {
1638+
return GetVersionOptions{
1639+
CustomVersion: &version,
16431640
}
16441641
}
16451642

1646-
// ExecuteWithMinVersion returns a GetVersionOption that makes GetVersion return minSupported version
1643+
// ExecuteWithMinVersion returns a GetVersionOptions that makes GetVersion return minSupported version
16471644
// when executed for the first time, instead of returning maxSupported version.
16481645
// To see how this option can be used, see the ExecuteWithVersion option
1649-
func ExecuteWithMinVersion() GetVersionOption {
1650-
return func(o *GetVersionOptions) {
1651-
o.UseMinVersion = true
1646+
func ExecuteWithMinVersion() GetVersionOptions {
1647+
return GetVersionOptions{
1648+
UseMinVersion: true,
16521649
}
16531650
}
16541651

@@ -1718,12 +1715,12 @@ func ExecuteWithMinVersion() GetVersionOption {
17181715
// } else {
17191716
// err = workflow.ExecuteActivity(ctx, qux, data).Get(ctx, nil)
17201717
// }
1721-
func GetVersion(ctx Context, changeID string, minSupported, maxSupported Version, opts ...GetVersionOption) Version {
1718+
func GetVersion(ctx Context, changeID string, minSupported, maxSupported Version, opts ...GetVersionOptions) Version {
17221719
i := getWorkflowInterceptor(ctx)
17231720
return i.GetVersion(ctx, changeID, minSupported, maxSupported, opts...)
17241721
}
17251722

1726-
func (wc *workflowEnvironmentInterceptor) GetVersion(ctx Context, changeID string, minSupported, maxSupported Version, opts ...GetVersionOption) Version {
1723+
func (wc *workflowEnvironmentInterceptor) GetVersion(ctx Context, changeID string, minSupported, maxSupported Version, opts ...GetVersionOptions) Version {
17271724
return wc.env.GetVersion(changeID, minSupported, maxSupported, opts...)
17281725
}
17291726

workflow/workflow.go

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ type (
4545
// Version represents a change version. See GetVersion call.
4646
Version = internal.Version
4747

48-
// GetVersionOption configures GetVersion behaviour
49-
GetVersionOption = internal.GetVersionOption
50-
5148
// ChildWorkflowOptions stores all child workflow specific parameters that will be stored inside of a Context.
5249
ChildWorkflowOptions = internal.ChildWorkflowOptions
5350

@@ -356,7 +353,7 @@ func MutableSideEffect(ctx Context, id string, f func(ctx Context) interface{},
356353
// DefaultVersion is a version returned by GetVersion for code that wasn't versioned before
357354
const DefaultVersion Version = internal.DefaultVersion
358355

359-
// ExecuteWithVersion returns a GetVersionOption that forces a specific version to be returned
356+
// ExecuteWithVersion returns a GetVersionOptions that forces a specific version to be returned
360357
// when executed for the first time, instead of returning maxSupported version.
361358
//
362359
// This option can be used when you want to separate the versioning of the workflow code and
@@ -412,19 +409,15 @@ const DefaultVersion Version = internal.DefaultVersion
412409
//
413410
// ExecuteWithVersion option is useful when you want to ensure that your changes can be safely rolled back if needed, as
414411
// both versions of the workflow code are compatible with each other.
415-
func ExecuteWithVersion(version Version) GetVersionOption {
416-
return func(o *internal.GetVersionOptions) {
417-
o.CustomVersion = &version
418-
}
412+
func ExecuteWithVersion(version Version) internal.GetVersionOptions {
413+
return internal.ExecuteWithVersion(version)
419414
}
420415

421-
// ExecuteWithMinVersion returns a GetVersionOption that makes GetVersion return minSupported version
416+
// ExecuteWithMinVersion returns a GetVersionOptions that makes GetVersion return minSupported version
422417
// when executed for the first time, instead of returning maxSupported version.
423418
// To see how this option can be used, see the ExecuteWithVersion option
424-
func ExecuteWithMinVersion() GetVersionOption {
425-
return func(o *internal.GetVersionOptions) {
426-
o.UseMinVersion = true
427-
}
419+
func ExecuteWithMinVersion() internal.GetVersionOptions {
420+
return internal.ExecuteWithMinVersion()
428421
}
429422

430423
// GetVersion is used to safely perform backwards incompatible changes to workflow definitions.
@@ -492,7 +485,7 @@ func ExecuteWithMinVersion() GetVersionOption {
492485
// } else {
493486
// err = workflow.ExecuteActivity(ctx, qux, data).Get(ctx, nil)
494487
// }
495-
func GetVersion(ctx Context, changeID string, minSupported, maxSupported Version, opts ...GetVersionOption) Version {
488+
func GetVersion(ctx Context, changeID string, minSupported, maxSupported Version, opts ...internal.GetVersionOptions) Version {
496489
return internal.GetVersion(ctx, changeID, minSupported, maxSupported, opts...)
497490
}
498491

0 commit comments

Comments
 (0)