Skip to content

Commit f69b146

Browse files
Allow worker to read results directly from the external SDK (#777)
1 parent e5ca2ba commit f69b146

File tree

7 files changed

+19
-39
lines changed

7 files changed

+19
-39
lines changed

src/DurableSDK/ExternalInvoker.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,21 @@
66
namespace Microsoft.Azure.Functions.PowerShellWorker.Durable
77
{
88
using System;
9+
using System.Collections;
910
using System.Management.Automation;
1011

1112
internal class ExternalInvoker : IExternalInvoker
1213
{
1314
private readonly Func<PowerShell, object> _externalSDKInvokerFunction;
14-
private readonly IPowerShellServices _powerShellServices;
1515

16-
public ExternalInvoker(Func<PowerShell, object> invokerFunction, IPowerShellServices powerShellServices)
16+
public ExternalInvoker(Func<PowerShell, object> invokerFunction)
1717
{
1818
_externalSDKInvokerFunction = invokerFunction;
19-
_powerShellServices = powerShellServices;
2019
}
2120

22-
public void Invoke()
21+
public Hashtable Invoke(IPowerShellServices powerShellServices)
2322
{
24-
_externalSDKInvokerFunction.Invoke(_powerShellServices.GetPowerShell());
23+
return (Hashtable)_externalSDKInvokerFunction.Invoke(powerShellServices.GetPowerShell());
2524
}
2625
}
2726
}

src/DurableSDK/IExternalInvoker.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55

66
namespace Microsoft.Azure.Functions.PowerShellWorker.Durable
77
{
8+
using System.Collections;
9+
810
// Represents a contract for the
911
internal interface IExternalInvoker
1012
{
1113
// Method to invoke an orchestration using the external Durable SDK
12-
void Invoke();
14+
Hashtable Invoke(IPowerShellServices powerShellServices);
1315
}
1416
}

src/DurableSDK/OrchestrationContext.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,6 @@ public class OrchestrationContext
3535

3636
internal OrchestrationActionCollector OrchestrationActionCollector { get; } = new OrchestrationActionCollector();
3737

38-
internal object ExternalSDKResult;
39-
40-
internal bool ExternalSDKIsError;
41-
42-
// Called by the External DF SDK to communicate its orchestration result
43-
// back to the worker.
44-
internal void SetExternalResult(object result, bool isError)
45-
{
46-
this.ExternalSDKResult = result;
47-
this.ExternalSDKIsError = isError;
48-
}
49-
5038
internal object CustomStatus { get; set; }
5139
}
5240
}

src/DurableSDK/OrchestrationInvoker.cs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace Microsoft.Azure.Functions.PowerShellWorker.Durable
1616
internal class OrchestrationInvoker : IOrchestrationInvoker
1717
{
1818
private IExternalInvoker _externalInvoker;
19+
internal static string isOrchestrationFailureKey = "IsOrchestrationFailure";
1920

2021
public Hashtable Invoke(
2122
OrchestrationBindingInfo orchestrationBindingInfo,
@@ -25,32 +26,24 @@ public Hashtable Invoke(
2526
{
2627
if (powerShellServices.UseExternalDurableSDK())
2728
{
28-
return InvokeExternalDurableSDK(orchestrationBindingInfo, powerShellServices);
29+
return InvokeExternalDurableSDK(powerShellServices);
2930
}
3031
return InvokeInternalDurableSDK(orchestrationBindingInfo, powerShellServices);
3132
}
33+
catch (Exception ex)
34+
{
35+
ex.Data.Add(isOrchestrationFailureKey, true);
36+
throw;
37+
}
3238
finally
3339
{
3440
powerShellServices.ClearStreamsAndCommands();
3541
}
3642
}
3743

38-
public Hashtable InvokeExternalDurableSDK(
39-
OrchestrationBindingInfo orchestrationBindingInfo,
40-
IPowerShellServices powerShellServices)
44+
public Hashtable InvokeExternalDurableSDK(IPowerShellServices powerShellServices)
4145
{
42-
43-
_externalInvoker.Invoke();
44-
var result = orchestrationBindingInfo.Context.ExternalSDKResult;
45-
var isError = orchestrationBindingInfo.Context.ExternalSDKIsError;
46-
if (isError)
47-
{
48-
throw (Exception)result;
49-
}
50-
else
51-
{
52-
return (Hashtable)result;
53-
}
46+
return _externalInvoker.Invoke(powerShellServices);
5447
}
5548

5649
public Hashtable InvokeInternalDurableSDK(

src/DurableSDK/PowerShellServices.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,10 @@ public OrchestrationBindingInfo SetOrchestrationContext(
9999
// The external SetFunctionInvocationContextCommand expects a .json string to deserialize
100100
// and writes an invoker function to the output pipeline.
101101
.AddParameter("OrchestrationContext", context.Data.String)
102-
.AddParameter("SetResult", (Action<object, bool>) orchestrationBindingInfo.Context.SetExternalResult)
103102
.InvokeAndClearCommands<Func<PowerShell, object>>();
104103
if (output.Count() == 1)
105104
{
106-
externalInvoker = new ExternalInvoker(output[0], this);
105+
externalInvoker = new ExternalInvoker(output[0]);
107106
}
108107
else
109108
{

src/PowerShell/PowerShellManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,9 @@ public Hashtable InvokeFunction(
243243
Logger.Log(isUserOnlyLog: true, LogLevel.Error, GetFunctionExceptionMessage(e));
244244
throw;
245245
}
246-
catch (OrchestrationFailureException e)
246+
catch (Exception e)
247247
{
248-
if (e.InnerException is IContainsErrorRecord inner)
248+
if (e.Data.Contains(OrchestrationInvoker.isOrchestrationFailureKey) && e.InnerException is IContainsErrorRecord inner)
249249
{
250250
Logger.Log(isUserOnlyLog: true, LogLevel.Error, GetFunctionExceptionMessage(inner));
251251
}

test/Unit/Durable/DurableControllerTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ public void TryGetInputBindingParameterValue_RetrievesOrchestrationContextParame
119119
{
120120
CreateParameterBinding(_contextParameterName, _orchestrationContext)
121121
};
122-
123122
_mockPowerShellServices.Setup(_ => _.SetOrchestrationContext(
124123
It.IsAny<ParameterBinding>(),
125124
out It.Ref<IExternalInvoker>.IsAny))

0 commit comments

Comments
 (0)