Skip to content

Commit cbf3fa3

Browse files
committed
initial commit
1 parent 169ff78 commit cbf3fa3

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

src/AzureFunctions.PowerShell.Durable.SDK.psm1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ function GetDurableClientFromModulePrivateData {
2222
}
2323
}
2424

25+
function GetInvocationIdFromModulePrivateData {
26+
$PrivateData = $PSCmdlet.MyInvocation.MyCommand.Module.PrivateData
27+
if ($null -eq $PrivateData -or $null -eq $PrivateData['InvocationId']) {
28+
# Return null instead of throwing - invocation ID is optional for correlation/tracing
29+
return $null
30+
}
31+
else {
32+
$PrivateData['InvocationId']
33+
}
34+
}
35+
2536
function Get-DurableStatus {
2637
[CmdletBinding()]
2738
param(
@@ -114,6 +125,8 @@ function Start-DurableOrchestration {
114125
}
115126

116127
$Body = $InputObject | ConvertTo-Json -Compress -Depth 100
128+
129+
$InvocationId = GetInvocationIdFromModulePrivateData
117130

118131
$null = Invoke-RestMethod -Uri $Uri -Method 'POST' -ContentType 'application/json' -Body $Body
119132

src/DurableEngine/Utilities/IPowerShellServices.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public interface IPowerShellServices
1313
{
1414
void SetDurableClient(object durableClient);
1515

16+
void SetInvocationId(string invocationId);
17+
1618
void SetOrchestrationContext(OrchestrationContext orchestrationContext);
1719

1820
void ClearOrchestrationContext();

src/DurableEngine/Utilities/PowerShellServices.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ public void SetDurableClient(object durableClient)
4545
_hasSetOrchestrationContext = true;
4646
}
4747

48+
public void SetInvocationId(string invocationId)
49+
{
50+
_pwsh.AddCommand(SetFunctionInvocationContextCommand)
51+
.AddParameter("InvocationId", invocationId)
52+
.InvokeAndClearCommands();
53+
54+
_hasSetOrchestrationContext = true;
55+
}
56+
4857
public void SetOrchestrationContext(OrchestrationContext orchestrationContext)
4958
{
5059
_pwsh.AddCommand(SetFunctionInvocationContextCommand)

src/DurableSDK/Commands/Internals/SetFunctionInvocationContextCommand.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class SetFunctionInvocationContextCommand : PSCmdlet
2323
{
2424
private const string ContextKey = "OrchestrationContext";
2525
private const string DurableClientKey = "DurableClient";
26+
private const string InvocationIdKey = "InvocationId";
2627

2728
/// <summary>
2829
/// The orchestration context.
@@ -36,6 +37,12 @@ public class SetFunctionInvocationContextCommand : PSCmdlet
3637
[Parameter(Mandatory = true, ParameterSetName = DurableClientKey)]
3738
public object DurableClient { get; set; }
3839

40+
/// <summary>
41+
/// The function invocation ID.
42+
/// </summary>
43+
[Parameter(Mandatory = true, ParameterSetName = InvocationIdKey)]
44+
public string InvocationId { get; set; }
45+
3946
/// <summary>
4047
/// Whether or not to clear the privateData of this module.
4148
/// </summary>
@@ -70,11 +77,16 @@ protected override void EndProcessing()
7077
privateData[DurableClientKey] = DurableClient;
7178
break;
7279

80+
case InvocationIdKey:
81+
privateData[InvocationIdKey] = InvocationId;
82+
break;
83+
7384
default:
7485
if (Clear.IsPresent)
7586
{
7687
privateData.Remove(ContextKey);
7788
privateData.Remove(DurableClientKey);
89+
privateData.Remove(InvocationIdKey);
7890
}
7991
break;
8092
}

0 commit comments

Comments
 (0)