@@ -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.
16371630func 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.
16461646func 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 {
0 commit comments