Skip to content

Commit b95c685

Browse files
authored
Add Version property to $Context (#85)
Add Version property to the `$Context` object passed to orchestrator functions, similar to Azure/azure-functions-powershell-worker#1108. As a result, PowerShell Functions users will be able to specify a version in **host.json**: ``` json { "extensions": { "durableTask": { "defaultVersion": "2.0" } } } ``` and check the orchestration version in their orchestrator functions in order to keep them backward compatible, for example: ``` powershell if ($Context.Version -eq '1.0') { # Legacy code path Invoke-DurableActivity 'A' } elseif ($Context.Version -eq '2.0') { # New code path Invoke-DurableActivity 'B' } ``` **Note: Microsoft.Azure.WebJobs.Extensions.DurableTask 3.1.0+ is required for this to work properly.** ### Pull request checklist * [x] My changes **do not** require documentation changes * [ ] Otherwise: Documentation issue linked to PR * [ ] My changes **should not** be added to the release notes for the next release * [x] Otherwise: I've added my notes to `release_notes.md` * [x] My changes **do not** need to be backported to a previous version * [ ] Otherwise: Backport tracked by issue/PR #issue_or_pr * [x] I have added all required tests (Unit tests, E2E tests)
1 parent 4252f43 commit b95c685

File tree

9 files changed

+22
-6
lines changed

9 files changed

+22
-6
lines changed

release_notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Add Version property to $Context

src/DurableEngine/DurableEngine.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.DurableTask.Client" Version="1.0.0" />
11-
<PackageReference Include="Microsoft.DurableTask.Worker" Version="1.0.0" />
10+
<PackageReference Include="Microsoft.DurableTask.Client" Version="1.10.0" />
11+
<PackageReference Include="Microsoft.DurableTask.Worker" Version="1.10.0" />
1212
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.2.1" PrivateAssets="all" />
1313
</ItemGroup>
1414
</Project>

src/DurableEngine/Models/OrchestrationContext.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class OrchestrationContext
2424
/// </summary>
2525
[DataMember]
2626
public object Input
27-
{
27+
{
2828
get => DTFxContext?.GetInput<object>();
2929
}
3030

@@ -77,5 +77,10 @@ public DateTime CurrentUtcDateTime
7777
/// </summary>
7878
[DataMember]
7979
internal HistoryEvent[] History { get; set; }
80+
81+
/// <summary>
82+
/// Gets the version of the current orchestration instance, which was set when the instance was created.
83+
/// </summary>
84+
public string Version => DTFxContext?.Version;
8085
}
8186
}

test/E2E/AzureFunctions.PowerShell.Durable.SDK.E2E/DurableClientTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ await ValidateDurableWorkflowResults(
8484
{
8585
Assert.Equal("Completed", (string)finalStatusResponseBody.runtimeStatus);
8686
Assert.Equal("Hello Tokyo", finalStatusResponseBody.output[0].ToString());
87-
Assert.Equal("Hello Seattle", finalStatusResponseBody.output[1].ToString());
87+
Assert.Equal("Context.Version: 1.0", finalStatusResponseBody.output[1].ToString());
88+
Assert.Equal("Hello Seattle", finalStatusResponseBody.output[2].ToString());
8889
});
8990
}
9091

test/E2E/AzureFunctions.PowerShell.Durable.SDK.E2E/OrchestrationTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ await ValidateDurableWorkflowResults(
7272
Assert.Equal("True", finalStatusResponseBody.output[0].ToString());
7373
Assert.Equal("Hello myInstanceId", finalStatusResponseBody.output[1].ToString());
7474
Assert.Equal("False", finalStatusResponseBody.output[2].ToString());
75+
Assert.Equal("1.0", finalStatusResponseBody.output[3].ToString());
7576
});
7677
}
7778
}

test/E2E/durableApp/DurableOrchestratorAccessContextProps/run.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ $output = @()
55
$output += $Context.IsReplaying
66
$output += Invoke-DurableActivity -FunctionName 'Hello' -Input $Context.InstanceId
77
$output += $Context.IsReplaying
8+
$output += $Context.Version
89
$output

test/E2E/durableApp/SimpleOrchestrator/run.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ $ErrorActionPreference = 'Stop'
77
$output = Invoke-DurableActivity -FunctionName "Hello" -Input "Tokyo"
88

99
$output
10+
11+
"Context.Version: $($Context.Version)"

test/E2E/durableApp/extensions.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>netcoreapp3.1</TargetFramework>
3+
<TargetFramework>net6.0</TargetFramework>
44
<WarningsAsErrors></WarningsAsErrors>
55
<DefaultItemExcludes>**</DefaultItemExcludes>
66
</PropertyGroup>
77
<ItemGroup>
8-
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="2.9.1" />
8+
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="3.1.0" />
99
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="5.1.1" />
1010
<PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="4.0.1" />
1111
</ItemGroup>

test/E2E/durableApp/host.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,10 @@
1010
},
1111
"managedDependency": {
1212
"enabled": true
13+
},
14+
"extensions": {
15+
"durableTask": {
16+
"defaultVersion": "1.0"
17+
}
1318
}
1419
}

0 commit comments

Comments
 (0)