15
15
16
16
namespace Microsoft . Azure . Functions . PowerShellWorker . PowerShell
17
17
{
18
+ using Microsoft . Azure . Functions . PowerShellWorker . DurableWorker ;
18
19
using System . Management . Automation ;
19
20
using System . Text ;
20
21
@@ -204,27 +205,38 @@ public Hashtable InvokeFunction(
204
205
FunctionInvocationPerformanceStopwatch stopwatch )
205
206
{
206
207
var outputBindings = FunctionMetadata . GetOutputBindingHashtable ( _pwsh . Runspace . InstanceId ) ;
207
- var durableController = new DurableController ( functionInfo . DurableFunctionInfo , _pwsh ) ;
208
+ var durableFunctionsUtils = new DurableController ( functionInfo . DurableFunctionInfo , _pwsh ) ;
208
209
209
210
try
210
211
{
211
-
212
- durableController . BeforeFunctionInvocation ( inputData ) ;
212
+ durableFunctionsUtils . InitializeBindings ( inputData ) ;
213
213
214
214
AddEntryPointInvocationCommand ( functionInfo ) ;
215
215
stopwatch . OnCheckpoint ( FunctionInvocationPerformanceStopwatch . Checkpoint . FunctionCodeReady ) ;
216
216
217
- SetInputBindingParameterValues ( functionInfo , inputData , durableController , triggerMetadata , traceContext , retryContext ) ;
217
+ var orchestrationParamName = durableFunctionsUtils . GetOrchestrationParameterName ( ) ;
218
+ SetInputBindingParameterValues ( functionInfo , inputData , orchestrationParamName , triggerMetadata , traceContext , retryContext ) ;
218
219
stopwatch . OnCheckpoint ( FunctionInvocationPerformanceStopwatch . Checkpoint . InputBindingValuesReady ) ;
219
220
220
221
stopwatch . OnCheckpoint ( FunctionInvocationPerformanceStopwatch . Checkpoint . InvokingFunctionCode ) ;
221
222
Logger . Log ( isUserOnlyLog : false , LogLevel . Trace , CreateInvocationPerformanceReportMessage ( functionInfo . FuncName , stopwatch ) ) ;
222
223
223
224
try
224
225
{
225
- return durableController . TryInvokeOrchestrationFunction ( out var result )
226
- ? result
227
- : InvokeNonOrchestrationFunction ( durableController , outputBindings ) ;
226
+ if ( functionInfo . DurableFunctionInfo . IsOrchestrationFunction )
227
+ {
228
+ return durableFunctionsUtils . InvokeOrchestrationFunction ( ) ;
229
+ }
230
+ else
231
+ {
232
+ var addPipelineOutput = functionInfo . DurableFunctionInfo . Type != DurableFunctionType . ActivityFunction ;
233
+ if ( addPipelineOutput )
234
+ {
235
+ _pwsh . AddCommand ( "Microsoft.Azure.Functions.PowerShellWorker\\ Trace-PipelineObject" ) ;
236
+ }
237
+ return ExecuteUserCode ( addPipelineOutput , outputBindings ) ;
238
+ }
239
+
228
240
}
229
241
catch ( RuntimeException e )
230
242
{
@@ -243,7 +255,8 @@ public Hashtable InvokeFunction(
243
255
}
244
256
finally
245
257
{
246
- durableController . AfterFunctionInvocation ( ) ;
258
+ // TODO: determine if external SDK also needs this call
259
+ durableFunctionsUtils . AfterFunctionInvocation ( ) ;
247
260
outputBindings . Clear ( ) ;
248
261
ResetRunspace ( ) ;
249
262
}
@@ -252,7 +265,7 @@ public Hashtable InvokeFunction(
252
265
private void SetInputBindingParameterValues (
253
266
AzFunctionInfo functionInfo ,
254
267
IEnumerable < ParameterBinding > inputData ,
255
- DurableController durableController ,
268
+ string orchParamName ,
256
269
Hashtable triggerMetadata ,
257
270
TraceContext traceContext ,
258
271
RetryContext retryContext )
@@ -261,10 +274,10 @@ private void SetInputBindingParameterValues(
261
274
{
262
275
if ( functionInfo . FuncParameters . TryGetValue ( binding . Name , out var paramInfo ) )
263
276
{
264
- if ( ! durableController . TryGetInputBindingParameterValue ( binding . Name , out var valueToUse ) )
277
+ if ( string . CompareOrdinal ( binding . Name , orchParamName ) != 0 )
265
278
{
266
279
var bindingInfo = functionInfo . InputBindings [ binding . Name ] ;
267
- valueToUse = Utils . TransformInBindingValueAsNeeded ( paramInfo , bindingInfo , binding . Data . ToObject ( ) ) ;
280
+ var valueToUse = Utils . TransformInBindingValueAsNeeded ( paramInfo , bindingInfo , binding . Data . ToObject ( ) ) ;
268
281
_pwsh . AddParameter ( binding . Name , valueToUse ) ;
269
282
}
270
283
else
@@ -297,11 +310,15 @@ private void SetInputBindingParameterValues(
297
310
/// <summary>
298
311
/// Execution a function fired by a trigger or an activity function scheduled by an orchestration.
299
312
/// </summary>
300
- private Hashtable InvokeNonOrchestrationFunction ( DurableController durableController , IDictionary outputBindings )
313
+ private Hashtable ExecuteUserCode ( bool addPipelineOutput , IDictionary outputBindings )
301
314
{
302
315
var pipelineItems = _pwsh . InvokeAndClearCommands < object > ( ) ;
303
316
var result = new Hashtable ( outputBindings , StringComparer . OrdinalIgnoreCase ) ;
304
- durableController . AddPipelineOutputIfNecessary ( pipelineItems , result ) ;
317
+ if ( addPipelineOutput )
318
+ {
319
+ var returnValue = FunctionReturnValueBuilder . CreateReturnValueFromFunctionOutput ( pipelineItems ) ;
320
+ result . Add ( AzFunctionInfo . DollarReturn , returnValue ) ;
321
+ }
305
322
return result ;
306
323
}
307
324
0 commit comments