public static async Task WarmUp(ScriptHost host) { // exercise the Node pipeline await NodeFunctionInvoker.InitializeAsync(); }
public static async Task WarmUp(WebHostSettings settings, IScriptEventManager eventManager) { var traceWriter = new FileTraceWriter(Path.Combine(settings.LogPath, "Host"), TraceLevel.Info); ScriptHost host = null; try { traceWriter.Info("Warm up started"); string rootPath = settings.ScriptPath; if (Directory.Exists(rootPath)) { Directory.Delete(rootPath, true); } Directory.CreateDirectory(rootPath); string content = ReadResourceString("Functions.host.json"); File.WriteAllText(Path.Combine(rootPath, "host.json"), content); // read in the C# function string functionPath = Path.Combine(rootPath, "Test-CSharp"); Directory.CreateDirectory(functionPath); content = ReadResourceString("Functions.Test_CSharp.function.json"); File.WriteAllText(Path.Combine(functionPath, "function.json"), content); content = ReadResourceString("Functions.Test_CSharp.run.csx"); File.WriteAllText(Path.Combine(functionPath, "run.csx"), content); traceWriter.Info("Warm up functions deployed"); ScriptHostConfiguration config = new ScriptHostConfiguration { RootScriptPath = rootPath, FileLoggingMode = FileLoggingMode.Never, RootLogPath = settings.LogPath, TraceWriter = traceWriter, FileWatchingEnabled = false }; config.HostConfig.StorageConnectionString = null; config.HostConfig.DashboardConnectionString = null; host = ScriptHost.Create(new NullScriptHostEnvironment(), eventManager, config, ScriptSettingsManager.Instance); traceWriter.Info(string.Format("Starting Host (Id={0})", host.ScriptConfig.HostConfig.HostId)); host.Start(); var arguments = new Dictionary <string, object> { { "input", "{}" } }; host.CallAsync("Test-CSharp", arguments).Wait(); host.Stop(); await NodeFunctionInvoker.InitializeAsync(); traceWriter.Info("Warm up succeeded"); } catch (Exception ex) { traceWriter.Error(string.Format("Warm up failed: {0}", ex)); } finally { host?.Dispose(); traceWriter.Dispose(); } }