Skip to content

Commit 1ecdc76

Browse files
committed
change description of ExecuteWithVersion and ExecuteWithMinVersion
1 parent 24c5b5f commit 1ecdc76

File tree

2 files changed

+67
-67
lines changed

2 files changed

+67
-67
lines changed

internal/workflow.go

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,40 +1578,35 @@ type GetVersionOptions struct {
15781578
UseMinVersion bool
15791579
}
15801580

1581-
// ExecuteWithVersion returns a GetVersionOptions that forces a specific version to be returned
1582-
// when executed for the first time, instead of returning maxSupported version.
1581+
// ExecuteWithVersion forces a specific version to be returned when GetVersion is executed for the first time,
1582+
// instead of returning maxSupported version. This option can be used when you want to separate the versioning of the workflow code and
1583+
// activation of the new logic in the workflow code, to ensure that your changes can be safely rolled back, if needed.
15831584
//
1584-
// This option can be used when you want to separate the versioning of the workflow code and
1585-
// activation of the new logic in the workflow code, to ensure that your changes can be safely rolled back
1586-
// if needed. For example, initially a workflow has the following code:
1585+
// For example, initially a workflow has the following code:
15871586
//
15881587
// err = workflow.ExecuteActivity(ctx, foo).Get(ctx, nil)
15891588
//
15901589
// It should be updated to:
15911590
//
15921591
// err = workflow.ExecuteActivity(ctx, bar).Get(ctx, nil)
15931592
//
1594-
// Step 1
1595-
// To roll out your changes safely, both versions of your workflow code should be compatible with each other.
1596-
// To achieve that, you can use GetVersion with ExecuteWithVersion option.
1597-
// When GetVersion is executed for the first time, it will return DefaultVersion instead of maxSupported version:
1593+
// Following the steps below, your changes will be forward and backward compatible, keeping possible a safe rollback
1594+
// to the previous version of the workflow code:
15981595
//
1599-
// v := GetVersion(ctx, "fooChange", DefaultVersion, 1, ExecuteWithVersion(DefaultVersion))
1596+
// 1. Keep execution of foo activity, add a support of bar activity
1597+
//
1598+
// v := GetVersion(ctx, "fooChange", DefaultVersion, 1, ExecuteWithVersion(DefaultVersion))
16001599
// if v == DefaultVersion {
1601-
// err = workflow.ExecuteActivity(ctx, foo).Get(ctx, nil)
1600+
// err = workflow.ExecuteActivity(ctx, foo).Get(ctx, nil)
16021601
// } else {
1603-
// err = workflow.ExecuteActivity(ctx, bar).Get(ctx, nil)
1602+
// err = workflow.ExecuteActivity(ctx, bar).Get(ctx, nil)
16041603
// }
16051604
//
1606-
// At this step, the previous version of the code supports only DefaultVersion, however new version of the code
1607-
// supports both DefaultVersion and 1. At the same time, the new version of the code is not yet activated,
1608-
// so the workflow started on the new version of the code will still execute foo activity - previous version of the code.
1609-
// This makes it possible to safely roll back your changes if needed, as the previous code supports DefaultVersion.
1605+
// The code above supports replaying of workflow execution with both versions DefaultVersion and 1.
1606+
// All new workflow executions will execute foo activity, because
1607+
// GetVersion with the ExecuteWithVersion option returns DefaultVersion, that will be recorded into the workflow history
16101608
//
1611-
// Step 2
1612-
// When the previous version of the code is no longer running, there is no need to start new workflow executions
1613-
// with DefaultVersion anymore, and you can the maxSupported version to activate the new code. To achieve that you can
1614-
// remove the usage of ExecuteWithVersion option. When GetVersion is executed for the first time, it will return maxSupported version:
1609+
// 2. Enable execution of bar activity
16151610
//
16161611
// v := GetVersion(ctx, "fooChange", DefaultVersion, 1)
16171612
// if v == DefaultVersion {
@@ -1620,29 +1615,34 @@ type GetVersionOptions struct {
16201615
// err = workflow.ExecuteActivity(ctx, bar).Get(ctx, nil)
16211616
// }
16221617
//
1623-
// At this step, the previous and old versions of the code support both versions DefaultVersion and 1,
1624-
// however the new version of the code is activated, so the workflow started on the new version of the code
1625-
// will execute bar activity - new version of the code. This makes it possible to safely roll back your changes if needed,
1626-
// because both versions of the code support both versions DefaultVersion and 1.
1618+
// The code above supports replaying of workflow execution with both versions DefaultVersion and 1.
1619+
// All new workflow executions will execute bar activity, because
1620+
// GetVersion returns the maximum supported version - 1, that will be recorded into the workflow history
16271621
//
1628-
// Step 3
1629-
// When there are no running previous version of the code and there are no workflow executions
1630-
// running DefaultVersion the correspondent branch can be removed:
1622+
// 3. Remove a support of foo activity:
16311623
//
16321624
// GetVersion(ctx, "fooChange", 1, 1)
16331625
// err = workflow.ExecuteActivity(ctx, bar).Get(ctx, nil)
16341626
//
1635-
// ExecuteWithVersion option is useful when you want to ensure that your changes can be safely rolled back if needed, as
1636-
// both versions of the workflow code are compatible with each other.
1627+
// When there are no workflow executions running DefaultVersion the support of foo activity can be removed.
1628+
//
1629+
// The ExecuteWithVersion option is useful when you want to ensure that your changes can be safely rolled back if needed.
16371630
func ExecuteWithVersion(version Version) GetVersionOptions {
16381631
return GetVersionOptions{
16391632
CustomVersion: &version,
16401633
}
16411634
}
16421635

1643-
// ExecuteWithMinVersion returns a GetVersionOptions that makes GetVersion return minSupported version
1644-
// when executed for the first time, instead of returning maxSupported version.
1645-
// To see how this option can be used, see the ExecuteWithVersion option
1636+
// ExecuteWithMinVersion forces minSupported version to be returned when GetVersion is executed for the first time,
1637+
// instead of returning maxSupported version. This option can be used when you want to separate
1638+
// the versioning of the workflow code and activation of the new logic in the workflow code,
1639+
// to ensure that your changes can be safely rolled back, if needed.
1640+
// 2 options below are equivalent to each other:
1641+
//
1642+
// GetVersion(ctx, "fooChange", 1, 2, ExecuteWithVersion(1))
1643+
// GetVersion(ctx, "fooChange", 1, 2, ExecuteWithMinVersion())
1644+
//
1645+
// Check the ExecuteWithVersion documentation for more details on how to use ExecuteWithMinVersion.
16461646
func ExecuteWithMinVersion() GetVersionOptions {
16471647
return GetVersionOptions{
16481648
UseMinVersion: true,
@@ -1700,14 +1700,14 @@ func ExecuteWithMinVersion() GetVersionOptions {
17001700
// err = workflow.ExecuteActivity(ctx, baz).Get(ctx, nil)
17011701
//
17021702
// The reason to keep it is: 1) it ensures that if there is older version execution still running, it will fail here
1703-
// and not proceed; 2) if you ever need to make more changes for fooChange, for example change activity from baz to qux,
1703+
// and not proceed; 2) if you ever need to make more changes for "fooChange", for example change activity from baz to qux,
17041704
// you just need to update the maxVersion from 2 to 3.
17051705
//
17061706
// Note that, you only need to preserve the first call to GetVersion() for each changeID. All subsequent call to GetVersion()
17071707
// with same changeID are safe to remove. However, if you really want to get rid of the first GetVersion() call as well,
1708-
// you can do so, but you need to make sure: 1) all older version executions are completed; 2) you can no longer use fooChange
1708+
// you can do so, but you need to make sure: 1) all older version executions are completed; 2) you can no longer use "fooChange"
17091709
// as changeID. If you ever need to make changes to that same part like change from baz to qux, you would need to use a
1710-
// different changeID like fooChange-fix2, and start minVersion from DefaultVersion again. The code would looks like:
1710+
// different changeID like "fooChange-fix2", and start minVersion from DefaultVersion again. The code would looks like:
17111711
//
17121712
// v := workflow.GetVersion(ctx, "fooChange-fix2", workflow.DefaultVersion, 1)
17131713
// if v == workflow.DefaultVersion {

workflow/workflow.go

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -353,40 +353,35 @@ func MutableSideEffect(ctx Context, id string, f func(ctx Context) interface{},
353353
// DefaultVersion is a version returned by GetVersion for code that wasn't versioned before
354354
const DefaultVersion Version = internal.DefaultVersion
355355

356-
// ExecuteWithVersion returns a GetVersionOptions that forces a specific version to be returned
357-
// when executed for the first time, instead of returning maxSupported version.
356+
// ExecuteWithVersion forces a specific version to be returned when GetVersion is executed for the first time,
357+
// instead of returning maxSupported version. This option can be used when you want to separate the versioning of the workflow code and
358+
// activation of the new logic in the workflow code, to ensure that your changes can be safely rolled back, if needed.
358359
//
359-
// This option can be used when you want to separate the versioning of the workflow code and
360-
// activation of the new logic in the workflow code, to ensure that your changes can be safely rolled back
361-
// if needed. For example, initially a workflow has the following code:
360+
// For example, initially a workflow has the following code:
362361
//
363362
// err = workflow.ExecuteActivity(ctx, foo).Get(ctx, nil)
364363
//
365364
// It should be updated to:
366365
//
367366
// err = workflow.ExecuteActivity(ctx, bar).Get(ctx, nil)
368367
//
369-
// Step 1
370-
// To roll out your changes safely, both versions of your workflow code should be compatible with each other.
371-
// To achieve that, you can use GetVersion with ExecuteWithVersion option.
372-
// When GetVersion is executed for the first time, it will return DefaultVersion instead of maxSupported version:
368+
// Following the steps below, your changes will be forward and backward compatible, keeping possible a safe rollback
369+
// to the previous version of the workflow code:
373370
//
374-
// v := GetVersion(ctx, "fooChange", DefaultVersion, 1, ExecuteWithVersion(DefaultVersion))
371+
// 1. Keep execution of foo activity, add a support of bar activity
372+
//
373+
// v := GetVersion(ctx, "fooChange", DefaultVersion, 1, ExecuteWithVersion(DefaultVersion))
375374
// if v == DefaultVersion {
376-
// err = workflow.ExecuteActivity(ctx, foo).Get(ctx, nil)
375+
// err = workflow.ExecuteActivity(ctx, foo).Get(ctx, nil)
377376
// } else {
378-
// err = workflow.ExecuteActivity(ctx, bar).Get(ctx, nil)
377+
// err = workflow.ExecuteActivity(ctx, bar).Get(ctx, nil)
379378
// }
380379
//
381-
// At this step, the previous version of the code supports only DefaultVersion, however new version of the code
382-
// supports both DefaultVersion and 1. At the same time, the new version of the code is not yet activated,
383-
// so the workflow started on the new version of the code will still execute foo activity - previous version of the code.
384-
// This makes it possible to safely roll back your changes if needed, as the previous code supports DefaultVersion.
380+
// The code above supports replaying of workflow execution with both versions DefaultVersion and 1.
381+
// All new workflow executions will execute foo activity, because
382+
// GetVersion with ExecuteWithMinVersion option returns DefaultVersion, that will be recorded into the workflow history
385383
//
386-
// Step 2
387-
// When the previous version of the code is no longer running, there is no need to start new workflow executions
388-
// with DefaultVersion anymore, and you can the maxSupported version to activate the new code. To achieve that you can
389-
// remove the usage of ExecuteWithVersion option. When GetVersion is executed for the first time, it will return maxSupported version:
384+
// 2. Enable execution of bar activity
390385
//
391386
// v := GetVersion(ctx, "fooChange", DefaultVersion, 1)
392387
// if v == DefaultVersion {
@@ -395,27 +390,32 @@ const DefaultVersion Version = internal.DefaultVersion
395390
// err = workflow.ExecuteActivity(ctx, bar).Get(ctx, nil)
396391
// }
397392
//
398-
// At this step, the previous and old versions of the code support both versions DefaultVersion and 1,
399-
// however the new version of the code is activated, so the workflow started on the new version of the code
400-
// will execute bar activity - new version of the code. This makes it possible to safely roll back your changes if needed,
401-
// because both versions of the code support both versions DefaultVersion and 1.
393+
// The code above supports replaying of workflow execution with both versions DefaultVersion and 1.
394+
// All new workflow executions will execute bar activity, because
395+
// GetVersion returns the maximum supported version - 1, that will be recorded into the workflow history
402396
//
403-
// Step 3
404-
// When there are no running previous version of the code and there are no workflow executions
405-
// running DefaultVersion the correspondent branch can be removed:
397+
// 3. Remove a support of foo activity:
406398
//
407399
// GetVersion(ctx, "fooChange", 1, 1)
408400
// err = workflow.ExecuteActivity(ctx, bar).Get(ctx, nil)
409401
//
410-
// ExecuteWithVersion option is useful when you want to ensure that your changes can be safely rolled back if needed, as
411-
// both versions of the workflow code are compatible with each other.
402+
// When there are no workflow executions running DefaultVersion the support of foo activity can be removed.
403+
//
404+
// ExecuteWithVersion option is useful when you want to ensure that your changes can be safely rolled back if needed.
412405
func ExecuteWithVersion(version Version) internal.GetVersionOptions {
413406
return internal.ExecuteWithVersion(version)
414407
}
415408

416-
// ExecuteWithMinVersion returns a GetVersionOptions that makes GetVersion return minSupported version
417-
// when executed for the first time, instead of returning maxSupported version.
418-
// To see how this option can be used, see the ExecuteWithVersion option
409+
// ExecuteWithMinVersion forces minSupported version to be returned when GetVersion is executed for the first time,
410+
// instead of returning maxSupported version. This option can be used when you want to separate
411+
// the versioning of the workflow code and activation of the new logic in the workflow code,
412+
// to ensure that your changes can be safely rolled back, if needed.
413+
// 2 options below are equivalent to each other:
414+
//
415+
// GetVersion(ctx, "fooChange", 1, 2, ExecuteWithVersion(1))
416+
// GetVersion(ctx, "fooChange", 1, 2, ExecuteWithMinVersion())
417+
//
418+
// Check the ExecuteWithVersion documentation, for more details on how to use ExecuteWithMinVersion.
419419
func ExecuteWithMinVersion() internal.GetVersionOptions {
420420
return internal.ExecuteWithMinVersion()
421421
}

0 commit comments

Comments
 (0)