Skip to content

Commit

Permalink
allow external SDK to set the user-code's input. Still need to refact…
Browse files Browse the repository at this point in the history
…or this logic for the worker to continue working with old SDK
  • Loading branch information
davidmrdavid committed Feb 4, 2022
1 parent 092e333 commit 506e4f7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
33 changes: 19 additions & 14 deletions src/DurableWorker/DurableController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,27 @@ public void BeforeFunctionInvocation(IList<ParameterBinding> inputData)
}
else if (_durableFunctionInfo.IsOrchestrationFunction)
{
_orchestrationBindingInfo = CreateOrchestrationBindingInfo(inputData);
_powerShellServices.SetOrchestrationContext(_orchestrationBindingInfo.Context);

// Bote: Cannot find the DurableSDK module here, somehow.
Collection<object> output2 = this.pwsh.AddCommand("Get-Module")
.InvokeAndClearCommands<object>();

var context = inputData[0];
Collection<Action<object>> output = this.pwsh.AddCommand("Set-BindingData")
.AddParameter("Input", context.Data.String)
.AddParameter("SetResult", (Action<object, bool>)_orchestrationBindingInfo.Context.SetExternalResult)
.InvokeAndClearCommands<Action<object>>();
if (output.Count() == 1)
try
{
this._orchestrationInvoker.SetExternalInvoker(output[0]);
_orchestrationBindingInfo = CreateOrchestrationBindingInfo(inputData);
var context = inputData[0];
Collection<Action<object>> output = this.pwsh.AddCommand("Set-BindingData")
.AddParameter("Input", context.Data.String)
.AddParameter("SetResult", (Action<object, bool>)_orchestrationBindingInfo.Context.SetExternalResult)
.InvokeAndClearCommands<Action<object>>();
if (output.Count() == 1)
{
this._orchestrationInvoker.SetExternalInvoker(output[0]);
}

_powerShellServices.SetOrchestrationContext(_orchestrationBindingInfo.Context);
}
catch
{
_orchestrationBindingInfo = CreateOrchestrationBindingInfo(inputData);
_powerShellServices.SetOrchestrationContext(_orchestrationBindingInfo.Context);
}

}
}

Expand Down
14 changes: 11 additions & 3 deletions src/PowerShell/PowerShellManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ public Hashtable InvokeFunction(

try
{

durableController.BeforeFunctionInvocation(inputData);

AddEntryPointInvocationCommand(functionInfo);
Expand All @@ -216,10 +217,11 @@ public Hashtable InvokeFunction(
SetInputBindingParameterValues(functionInfo, inputData, durableController, triggerMetadata, traceContext, retryContext);
stopwatch.OnCheckpoint(FunctionInvocationPerformanceStopwatch.Checkpoint.InputBindingValuesReady);

if (!durableController.ShouldSuppressPipelineTraces())
/* This has been moved to the DF SDK (although it should also be moved down within the worker)
* if (!durableController.ShouldSuppressPipelineTraces())
{
_pwsh.AddCommand("Microsoft.Azure.Functions.PowerShellWorker\\Trace-PipelineObject");
}
}*/

stopwatch.OnCheckpoint(FunctionInvocationPerformanceStopwatch.Checkpoint.InvokingFunctionCode);
Logger.Log(isUserOnlyLog: false, LogLevel.Trace, CreateInvocationPerformanceReportMessage(functionInfo.FuncName, stopwatch));
Expand Down Expand Up @@ -270,9 +272,15 @@ private void SetInputBindingParameterValues(
{
var bindingInfo = functionInfo.InputBindings[binding.Name];
valueToUse = Utils.TransformInBindingValueAsNeeded(paramInfo, bindingInfo, binding.Data.ToObject());
_pwsh.AddParameter(binding.Name, valueToUse);
}
else
{
// move this further down in the worker
// _pwsh.AddParameter(binding.Name, valueToUse);

}

_pwsh.AddParameter(binding.Name, valueToUse);
}
}

Expand Down

0 comments on commit 506e4f7

Please sign in to comment.