Beispiel #1
0
        private async Task BindOutputsAsync(object input, Binder binder, ScriptInvocationResult result)
        {
            if (_outputBindings == null)
            {
                return;
            }

            _handleScriptReturnValue(result);

            var outputBindingTasks = _outputBindings.Select(async binding =>
            {
                // apply the value to the binding
                if (result.Outputs.TryGetValue(binding.Metadata.Name, out object value) && value != null)
                {
                    BindingContext bindingContext = new BindingContext
                    {
                        TriggerValue = input,
                        Binder       = binder,
                        BindingData  = binder.BindingData,
                        Value        = value
                    };
                    await binding.BindAsync(bindingContext).ConfigureAwait(false);
                }
            });

            await Task.WhenAll(outputBindingTasks);
        }
Beispiel #2
0
 private void HandleOutputDictionary(ScriptInvocationResult result)
 {
     if (result.Return is JObject returnJson)
     {
         foreach (var pair in returnJson)
         {
             result.Outputs[pair.Key] = pair.Value.ToObject <object>();
         }
     }
 }
        protected override async Task <object> InvokeCore(object[] parameters, FunctionInvocationContext context)
        {
            // Need to wait for atleast one language worker process to be initialized before accepting invocations
            await DelayUntilFunctionDispatcherInitialized();

            string invocationId = context.ExecutionContext.InvocationId.ToString();

            // TODO: fix extensions and remove
            object triggerValue = TransformInput(parameters[0], context.Binder.BindingData);
            var    triggerInput = (_bindingMetadata.Name, _bindingMetadata.DataType ?? DataType.String, triggerValue);
            var    inputs = new[] { triggerInput }.Concat(await BindInputsAsync(context.Binder));

            ScriptInvocationContext invocationContext = new ScriptInvocationContext()
            {
                FunctionMetadata      = Metadata,
                BindingData           = context.Binder.BindingData, // This has duplicates too (of type DefaultHttpRequest). Needs to be removed after verifying this can indeed be constructed by the workers from the rest of the data being passed (https://github.com/Azure/azure-functions-host/issues/4735).
                ExecutionContext      = context.ExecutionContext,
                Inputs                = inputs,
                ResultSource          = new TaskCompletionSource <ScriptInvocationResult>(),
                AsyncExecutionContext = System.Threading.ExecutionContext.Capture(),
                Traceparent           = Activity.Current?.Id,
                Tracestate            = Activity.Current?.TraceStateString,
                Attributes            = Activity.Current?.Tags,

                // TODO: link up cancellation token to parameter descriptors
                CancellationToken = CancellationToken.None,
                Logger            = context.Logger
            };

            _logger.LogDebug($"Sending invocation id:{invocationId}");
            await _functionDispatcher.InvokeAsync(invocationContext);

            ScriptInvocationResult result             = await invocationContext.ResultSource.Task;

            await BindOutputsAsync(triggerValue, context.Binder, result);

            return(result.Return);
        }
Beispiel #4
0
 private void HandleReturnParameter(ScriptInvocationResult result)
 {
     result.Outputs[ScriptConstants.SystemReturnParameterBindingName] = result.Return;
 }