Esempio n. 1
0
        private async Task <MethodInfo> CreateFunctionTarget(CancellationToken cancellationToken)
        {
            try
            {
                await VerifyPackageReferencesAsync();

                string eventName = string.Format(MetricEventNames.FunctionCompileLatencyByLanguageFormat, _compilationService.Language);
                using (_metricsLogger.LatencyEvent(eventName))
                {
                    IDotNetCompilation compilation = await _compilationService.GetFunctionCompilationAsync(Metadata);

                    Assembly assembly = compilation.Emit(cancellationToken);
                    _assemblyLoader.CreateOrUpdateContext(Metadata, assembly, _metadataResolver, TraceWriter, Host.ScriptConfig.HostConfig.LoggerFactory);

                    FunctionSignature functionSignature = compilation.GetEntryPointSignature(_functionEntryPointResolver);

                    ImmutableArray <Diagnostic> bindingDiagnostics = ValidateFunctionBindingArguments(functionSignature, _triggerInputName, _inputBindings, _outputBindings, throwIfFailed: true);
                    TraceCompilationDiagnostics(bindingDiagnostics);

                    // Set our function entry point signature
                    _functionSignature = functionSignature;

                    return(_functionSignature.GetMethod(assembly));
                }
            }
            catch (CompilationErrorException exc)
            {
                ImmutableArray <Diagnostic> diagnostics = AddFunctionDiagnostics(exc.Diagnostics);

                // Here we only need to trace to system logs
                TraceCompilationDiagnostics(diagnostics, LogTargets.System);

                throw new CompilationErrorException(exc.Message, diagnostics);
            }
        }
Esempio n. 2
0
        private async Task ReloadScriptAsync()
        {
            // Reset cached function
            _functionLoader.Reset();
            _compilerErrorCount = 0;
            LogOnPrimaryHost(string.Format(CultureInfo.InvariantCulture, "Script for function '{0}' changed. Reloading.", Metadata.Name), LogLevel.Information);

            ImmutableArray <Diagnostic> compilationResult = ImmutableArray <Diagnostic> .Empty;
            FunctionSignature           signature         = null;

            try
            {
                IDotNetCompilation compilation = await _compilationService.GetFunctionCompilationAsync(Metadata);

                compilationResult = compilation.GetDiagnostics();

                // TODO: Invoking this without the assembly is not supported by all compilations
                signature         = compilation.GetEntryPointSignature(_functionEntryPointResolver, null);
                compilationResult = ValidateFunctionBindingArguments(signature, _triggerInputName, _inputBindings, _outputBindings, compilationResult.ToBuilder());
            }
            catch (CompilationErrorException exc)
            {
                compilationResult = AddFunctionDiagnostics(compilationResult.AddRange(exc.Diagnostics));
            }

            TraceCompilationDiagnostics(compilationResult, LogTargets.User);

            bool compilationSucceeded = !compilationResult.Any(d => d.Severity == DiagnosticSeverity.Error);

            LogOnPrimaryHost(string.Format(CultureInfo.InvariantCulture, "Compilation {0}.", compilationSucceeded ? "succeeded" : "failed"), LogLevel.Information);

            // If the compilation succeeded, AND:
            //  - We haven't cached a function (failed to compile on load), OR
            //  - We're referencing local function types (i.e. POCOs defined in the function) AND Our our function signature has changed
            // Restart our host.
            if (compilationSucceeded &&
                (_functionSignature == null ||
                 (_functionSignature.HasLocalTypeReference || !_functionSignature.Equals(signature))))
            {
                await Host.RestartAsync().ConfigureAwait(false);
            }
        }