Пример #1
0
        protected override async Task <object> InvokeCore(object[] parameters, FunctionInvocationContext context)
        {
            // Need to wait for at least one language worker process to be initialized before accepting invocations
            if (!IsDispatcherReady())
            {
                await DelayUntilFunctionDispatcherInitializedOrShutdown();
            }

            var    bindingData  = context.Binder.BindingData;
            object triggerValue = TransformInput(parameters[0], bindingData);
            var    triggerInput = (_bindingMetadata.Name, _bindingMetadata.DataType ?? DataType.String, triggerValue);
            IEnumerable <(string, DataType, object)> inputs = new[] { triggerInput };

            if (_inputBindings.Count > 1)
            {
                var nonTriggerInputs = await BindInputsAsync(context.Binder);

                inputs = inputs.Concat(nonTriggerInputs);
            }

            var invocationContext = new ScriptInvocationContext
            {
                FunctionMetadata      = Metadata,
                BindingData           = bindingData,
                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
            };

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

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

            var result = await invocationContext.ResultSource.Task;

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

            return(result.Return);
        }
        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);
        }