All NodeServices invocations now have a default timeout, plus a descriptive exception if that happens

This commit is contained in:
SteveSandersonMS
2016-09-08 12:08:42 +01:00
parent 2799861296
commit 041d173f56
5 changed files with 81 additions and 14 deletions

View File

@@ -29,11 +29,11 @@ namespace Microsoft.AspNetCore.NodeServices
{
case NodeHostingModel.Http:
return new HttpNodeInstance(options.ProjectPath, options.WatchFileExtensions, options.NodeInstanceOutputLogger,
options.EnvironmentVariables, options.LaunchWithDebugging, options.DebuggingPort, /* port */ 0);
options.EnvironmentVariables, options.InvocationTimeoutMilliseconds, options.LaunchWithDebugging, options.DebuggingPort, /* port */ 0);
case NodeHostingModel.Socket:
var pipeName = "pni-" + Guid.NewGuid().ToString("D"); // Arbitrary non-clashing string
return new SocketNodeInstance(options.ProjectPath, options.WatchFileExtensions, pipeName, options.NodeInstanceOutputLogger,
options.EnvironmentVariables, options.LaunchWithDebugging, options.DebuggingPort);
options.EnvironmentVariables, options.InvocationTimeoutMilliseconds, options.LaunchWithDebugging, options.DebuggingPort);
default:
throw new ArgumentException("Unknown hosting model: " + options.HostingModel);
}

View File

@@ -11,6 +11,8 @@ namespace Microsoft.AspNetCore.NodeServices
public class NodeServicesOptions
{
public const NodeHostingModel DefaultNodeHostingModel = NodeHostingModel.Http;
internal const string TimeoutConfigPropertyName = nameof(InvocationTimeoutMilliseconds);
private const int DefaultInvocationTimeoutMilliseconds = 60 * 1000;
private const string LogCategoryName = "Microsoft.AspNetCore.NodeServices";
private static readonly string[] DefaultWatchFileExtensions = { ".js", ".jsx", ".ts", ".tsx", ".json", ".html" };
@@ -22,6 +24,7 @@ namespace Microsoft.AspNetCore.NodeServices
}
EnvironmentVariables = new Dictionary<string, string>();
InvocationTimeoutMilliseconds = DefaultInvocationTimeoutMilliseconds;
HostingModel = DefaultNodeHostingModel;
WatchFileExtensions = (string[])DefaultWatchFileExtensions.Clone();
@@ -49,5 +52,6 @@ namespace Microsoft.AspNetCore.NodeServices
public bool LaunchWithDebugging { get; set; }
public IDictionary<string, string> EnvironmentVariables { get; set; }
public int DebuggingPort { get; set; }
public int InvocationTimeoutMilliseconds { get; set; }
}
}