Skip to content

Commit 506e4f7

Browse files
committed
allow external SDK to set the user-code's input. Still need to refactor this logic for the worker to continue working with old SDK
1 parent 092e333 commit 506e4f7

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

src/DurableWorker/DurableController.cs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,27 @@ public void BeforeFunctionInvocation(IList<ParameterBinding> inputData)
6666
}
6767
else if (_durableFunctionInfo.IsOrchestrationFunction)
6868
{
69-
_orchestrationBindingInfo = CreateOrchestrationBindingInfo(inputData);
70-
_powerShellServices.SetOrchestrationContext(_orchestrationBindingInfo.Context);
71-
72-
// Bote: Cannot find the DurableSDK module here, somehow.
73-
Collection<object> output2 = this.pwsh.AddCommand("Get-Module")
74-
.InvokeAndClearCommands<object>();
75-
76-
var context = inputData[0];
77-
Collection<Action<object>> output = this.pwsh.AddCommand("Set-BindingData")
78-
.AddParameter("Input", context.Data.String)
79-
.AddParameter("SetResult", (Action<object, bool>)_orchestrationBindingInfo.Context.SetExternalResult)
80-
.InvokeAndClearCommands<Action<object>>();
81-
if (output.Count() == 1)
69+
try
8270
{
83-
this._orchestrationInvoker.SetExternalInvoker(output[0]);
71+
_orchestrationBindingInfo = CreateOrchestrationBindingInfo(inputData);
72+
var context = inputData[0];
73+
Collection<Action<object>> output = this.pwsh.AddCommand("Set-BindingData")
74+
.AddParameter("Input", context.Data.String)
75+
.AddParameter("SetResult", (Action<object, bool>)_orchestrationBindingInfo.Context.SetExternalResult)
76+
.InvokeAndClearCommands<Action<object>>();
77+
if (output.Count() == 1)
78+
{
79+
this._orchestrationInvoker.SetExternalInvoker(output[0]);
80+
}
81+
82+
_powerShellServices.SetOrchestrationContext(_orchestrationBindingInfo.Context);
8483
}
84+
catch
85+
{
86+
_orchestrationBindingInfo = CreateOrchestrationBindingInfo(inputData);
87+
_powerShellServices.SetOrchestrationContext(_orchestrationBindingInfo.Context);
88+
}
89+
8590
}
8691
}
8792

src/PowerShell/PowerShellManager.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ public Hashtable InvokeFunction(
208208

209209
try
210210
{
211+
211212
durableController.BeforeFunctionInvocation(inputData);
212213

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

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

224226
stopwatch.OnCheckpoint(FunctionInvocationPerformanceStopwatch.Checkpoint.InvokingFunctionCode);
225227
Logger.Log(isUserOnlyLog: false, LogLevel.Trace, CreateInvocationPerformanceReportMessage(functionInfo.FuncName, stopwatch));
@@ -270,9 +272,15 @@ private void SetInputBindingParameterValues(
270272
{
271273
var bindingInfo = functionInfo.InputBindings[binding.Name];
272274
valueToUse = Utils.TransformInBindingValueAsNeeded(paramInfo, bindingInfo, binding.Data.ToObject());
275+
_pwsh.AddParameter(binding.Name, valueToUse);
276+
}
277+
else
278+
{
279+
// move this further down in the worker
280+
// _pwsh.AddParameter(binding.Name, valueToUse);
281+
273282
}
274283

275-
_pwsh.AddParameter(binding.Name, valueToUse);
276284
}
277285
}
278286

0 commit comments

Comments
 (0)