diff --git a/src/DurableSDK/ExternalInvoker.cs b/src/DurableSDK/ExternalInvoker.cs index f0a73b86..fa8a31c6 100644 --- a/src/DurableSDK/ExternalInvoker.cs +++ b/src/DurableSDK/ExternalInvoker.cs @@ -6,22 +6,21 @@ namespace Microsoft.Azure.Functions.PowerShellWorker.Durable { using System; + using System.Collections; using System.Management.Automation; internal class ExternalInvoker : IExternalInvoker { private readonly Func _externalSDKInvokerFunction; - private readonly IPowerShellServices _powerShellServices; - public ExternalInvoker(Func invokerFunction, IPowerShellServices powerShellServices) + public ExternalInvoker(Func invokerFunction) { _externalSDKInvokerFunction = invokerFunction; - _powerShellServices = powerShellServices; } - public void Invoke() + public Hashtable Invoke(IPowerShellServices powerShellServices) { - _externalSDKInvokerFunction.Invoke(_powerShellServices.GetPowerShell()); + return (Hashtable)_externalSDKInvokerFunction.Invoke(powerShellServices.GetPowerShell()); } } } diff --git a/src/DurableSDK/IExternalInvoker.cs b/src/DurableSDK/IExternalInvoker.cs index 16d17e23..3a703f3d 100644 --- a/src/DurableSDK/IExternalInvoker.cs +++ b/src/DurableSDK/IExternalInvoker.cs @@ -5,10 +5,12 @@ namespace Microsoft.Azure.Functions.PowerShellWorker.Durable { + using System.Collections; + // Represents a contract for the internal interface IExternalInvoker { // Method to invoke an orchestration using the external Durable SDK - void Invoke(); + Hashtable Invoke(IPowerShellServices powerShellServices); } } diff --git a/src/DurableSDK/OrchestrationContext.cs b/src/DurableSDK/OrchestrationContext.cs index e7edec60..27f082db 100644 --- a/src/DurableSDK/OrchestrationContext.cs +++ b/src/DurableSDK/OrchestrationContext.cs @@ -35,18 +35,6 @@ public class OrchestrationContext internal OrchestrationActionCollector OrchestrationActionCollector { get; } = new OrchestrationActionCollector(); - internal object ExternalSDKResult; - - internal bool ExternalSDKIsError; - - // Called by the External DF SDK to communicate its orchestration result - // back to the worker. - internal void SetExternalResult(object result, bool isError) - { - this.ExternalSDKResult = result; - this.ExternalSDKIsError = isError; - } - internal object CustomStatus { get; set; } } } diff --git a/src/DurableSDK/OrchestrationInvoker.cs b/src/DurableSDK/OrchestrationInvoker.cs index 4706c2c3..b71116b4 100644 --- a/src/DurableSDK/OrchestrationInvoker.cs +++ b/src/DurableSDK/OrchestrationInvoker.cs @@ -16,6 +16,7 @@ namespace Microsoft.Azure.Functions.PowerShellWorker.Durable internal class OrchestrationInvoker : IOrchestrationInvoker { private IExternalInvoker _externalInvoker; + internal static string isOrchestrationFailureKey = "IsOrchestrationFailure"; public Hashtable Invoke( OrchestrationBindingInfo orchestrationBindingInfo, @@ -25,32 +26,24 @@ public Hashtable Invoke( { if (powerShellServices.UseExternalDurableSDK()) { - return InvokeExternalDurableSDK(orchestrationBindingInfo, powerShellServices); + return InvokeExternalDurableSDK(powerShellServices); } return InvokeInternalDurableSDK(orchestrationBindingInfo, powerShellServices); } + catch (Exception ex) + { + ex.Data.Add(isOrchestrationFailureKey, true); + throw; + } finally { powerShellServices.ClearStreamsAndCommands(); } } - public Hashtable InvokeExternalDurableSDK( - OrchestrationBindingInfo orchestrationBindingInfo, - IPowerShellServices powerShellServices) + public Hashtable InvokeExternalDurableSDK(IPowerShellServices powerShellServices) { - - _externalInvoker.Invoke(); - var result = orchestrationBindingInfo.Context.ExternalSDKResult; - var isError = orchestrationBindingInfo.Context.ExternalSDKIsError; - if (isError) - { - throw (Exception)result; - } - else - { - return (Hashtable)result; - } + return _externalInvoker.Invoke(powerShellServices); } public Hashtable InvokeInternalDurableSDK( diff --git a/src/DurableSDK/PowerShellServices.cs b/src/DurableSDK/PowerShellServices.cs index 2a403c1a..549d4417 100644 --- a/src/DurableSDK/PowerShellServices.cs +++ b/src/DurableSDK/PowerShellServices.cs @@ -99,11 +99,10 @@ public OrchestrationBindingInfo SetOrchestrationContext( // The external SetFunctionInvocationContextCommand expects a .json string to deserialize // and writes an invoker function to the output pipeline. .AddParameter("OrchestrationContext", context.Data.String) - .AddParameter("SetResult", (Action) orchestrationBindingInfo.Context.SetExternalResult) .InvokeAndClearCommands>(); if (output.Count() == 1) { - externalInvoker = new ExternalInvoker(output[0], this); + externalInvoker = new ExternalInvoker(output[0]); } else { diff --git a/src/PowerShell/PowerShellManager.cs b/src/PowerShell/PowerShellManager.cs index c604da81..0344c05d 100644 --- a/src/PowerShell/PowerShellManager.cs +++ b/src/PowerShell/PowerShellManager.cs @@ -243,9 +243,9 @@ public Hashtable InvokeFunction( Logger.Log(isUserOnlyLog: true, LogLevel.Error, GetFunctionExceptionMessage(e)); throw; } - catch (OrchestrationFailureException e) + catch (Exception e) { - if (e.InnerException is IContainsErrorRecord inner) + if (e.Data.Contains(OrchestrationInvoker.isOrchestrationFailureKey) && e.InnerException is IContainsErrorRecord inner) { Logger.Log(isUserOnlyLog: true, LogLevel.Error, GetFunctionExceptionMessage(inner)); } diff --git a/test/Unit/Durable/DurableControllerTests.cs b/test/Unit/Durable/DurableControllerTests.cs index e16f04d7..b57cb767 100644 --- a/test/Unit/Durable/DurableControllerTests.cs +++ b/test/Unit/Durable/DurableControllerTests.cs @@ -119,7 +119,6 @@ public void TryGetInputBindingParameterValue_RetrievesOrchestrationContextParame { CreateParameterBinding(_contextParameterName, _orchestrationContext) }; - _mockPowerShellServices.Setup(_ => _.SetOrchestrationContext( It.IsAny(), out It.Ref.IsAny))