Browse Source

support for specifying which dotnet service to watch

pull/1568/head
razvan.goga@gmail.com 3 years ago
parent
commit
fb422f5c8f
  1. 3
      src/Microsoft.Tye.Core/HostOptions.cs
  2. 14
      src/Microsoft.Tye.Hosting/ProcessRunner.cs
  3. 20
      src/Microsoft.Tye.Hosting/ProcessRunnerOptions.cs
  4. 4
      src/tye/Program.RunCommand.cs
  5. 11
      test/E2ETest/TyeRunTests.cs

3
src/Microsoft.Tye.Core/HostOptions.cs

@ -11,6 +11,7 @@ namespace Microsoft.Tye
public bool Dashboard { get; set; }
public List<string> Debug { get; } = new List<string>();
public List<string> Watch { get; } = new List<string>();
public string? DistributedTraceProvider { get; set; }
@ -25,7 +26,5 @@ namespace Microsoft.Tye
public int? Port { get; set; }
public Verbosity LogVerbosity { get; set; } = Verbosity.Debug;
public bool Watch { get; set; }
}
}

14
src/Microsoft.Tye.Hosting/ProcessRunner.cs

@ -218,7 +218,7 @@ namespace Microsoft.Tye.Hosting
application.PopulateEnvironment(service, (k, v) => environment[k] = v);
if (_options.DebugMode && (_options.DebugAllServices || _options.ServicesToDebug!.Contains(serviceName, StringComparer.OrdinalIgnoreCase)))
if (_options.ShouldDebugService(serviceName))
{
environment["DOTNET_STARTUP_HOOKS"] = typeof(Hosting.Runtime.HostingRuntimeHelpers).Assembly.Location;
}
@ -267,7 +267,7 @@ namespace Microsoft.Tye.Hosting
status.StoppingTokenSource = stoppingCts;
await using var _ = processInfo.StoppedTokenSource.Token.Register(() => status.StoppingTokenSource.Cancel());
if (!_options.Watch)
if (!_options.ShouldWatchService(serviceName))
{
service.Replicas[replica] = status;
service.ReplicaEvents.OnNext(new ReplicaEvent(ReplicaState.Added, status));
@ -327,7 +327,7 @@ namespace Microsoft.Tye.Hosting
WriteReplicaToStore(pid.ToString());
if (_options.Watch)
if (_options.ShouldWatchService(serviceName))
{
// OnStart/OnStop will be called multiple times for watch.
// Watch will constantly be adding and removing from the list, so only add here for watch.
@ -346,7 +346,7 @@ namespace Microsoft.Tye.Hosting
service.ReplicaEvents.OnNext(new ReplicaEvent(ReplicaState.Stopped, status));
}
if (!_options.Watch)
if (!_options.ShouldWatchService(serviceName))
{
// Only increase backoff when not watching project as watch will wait for file changes before rebuild.
backOff *= 2;
@ -375,7 +375,7 @@ namespace Microsoft.Tye.Hosting
}
};
if (_options.Watch && (service.Description.RunInfo is ProjectRunInfo runInfo))
if (_options.ShouldWatchService(serviceName) && (service.Description.RunInfo is ProjectRunInfo runInfo))
{
var projectFile = runInfo.ProjectFile.FullName;
var fileSetFactory = new MsBuildFileSetFactory(_logger,
@ -387,7 +387,7 @@ namespace Microsoft.Tye.Hosting
await new DotNetWatcher(_logger)
.WatchAsync(processInfo, fileSetFactory, replica, status.StoppingTokenSource.Token);
}
else if (_options.Watch && (service.Description.RunInfo is AzureFunctionRunInfo azureFunctionRunInfo) && !string.IsNullOrEmpty(azureFunctionRunInfo.ProjectFile))
else if (_options.ShouldWatchService(serviceName) && (service.Description.RunInfo is AzureFunctionRunInfo azureFunctionRunInfo) && !string.IsNullOrEmpty(azureFunctionRunInfo.ProjectFile))
{
var projectFile = azureFunctionRunInfo.ProjectFile;
var fileSetFactory = new MsBuildFileSetFactory(_logger,
@ -408,7 +408,7 @@ namespace Microsoft.Tye.Hosting
{
_logger.LogError(0, ex, "Failed to launch process for service {ServiceName}", replica);
if (!_options.Watch)
if (!_options.ShouldWatchService(serviceName))
{
// Only increase backoff when not watching project as watch will wait for file changes before rebuild.
backOff *= 2;

20
src/Microsoft.Tye.Hosting/ProcessRunnerOptions.cs

@ -9,21 +9,33 @@ namespace Microsoft.Tye.Hosting
{
public class ProcessRunnerOptions
{
public bool DebugMode { get; set; }
public const string AllServices = "*";
public bool BuildProjects { get; set; }
public bool DebugMode { get; set; }
public string[]? ServicesToDebug { get; set; }
public bool DebugAllServices { get; set; }
public bool Watch { get; set; }
public bool ShouldDebugService (string serviceName) => DebugMode && (DebugAllServices || ServicesToDebug!.Contains(serviceName, StringComparer.OrdinalIgnoreCase));
public bool WatchMode { get; set; }
public string[]? ServicesToWatch { get; set; }
public bool WatchAllServices { get; set; }
public bool ShouldWatchService(string serviceName) => WatchMode && (WatchAllServices || ServicesToWatch!.Contains(serviceName, StringComparer.OrdinalIgnoreCase));
public static ProcessRunnerOptions FromHostOptions(HostOptions options)
{
return new ProcessRunnerOptions
{
BuildProjects = !options.NoBuild,
DebugMode = options.Debug.Any(),
ServicesToDebug = options.Debug.ToArray(),
DebugAllServices = options.Debug?.Contains("*", StringComparer.OrdinalIgnoreCase) ?? false,
Watch = options.Watch
DebugAllServices = options.Debug?.Contains(AllServices, StringComparer.OrdinalIgnoreCase) ?? false,
WatchMode = options.Watch.Any(),
ServicesToWatch = options.Watch.ToArray(),
WatchAllServices = options.Watch?.Contains(AllServices, StringComparer.OrdinalIgnoreCase) ?? false,
};
}
}

4
src/tye/Program.RunCommand.cs

@ -111,9 +111,9 @@ namespace Microsoft.Tye
LoggingProvider = args.Logs,
MetricsProvider = args.Metrics,
LogVerbosity = args.Verbosity,
Watch = args.Watch
};
options.Debug.AddRange(args.Debug);
options.Watch.AddRange(args.Watch);
await application.ProcessExtensionsAsync(options, output, ExtensionContext.OperationKind.LocalRun);
@ -170,7 +170,7 @@ namespace Microsoft.Tye
public Verbosity Verbosity { get; set; }
public bool Watch { get; set; }
public string[] Watch { get; set; } = Array.Empty<string>();
public string Framework { get; set; } = default!;

11
test/E2ETest/TyeRunTests.cs

@ -19,7 +19,6 @@ using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Primitives;
using Microsoft.Tye;
using Microsoft.Tye.Hosting;
using Microsoft.Tye.Hosting.Model;
@ -353,7 +352,10 @@ services:
var client = new HttpClient(new RetryHandler(handler));
await RunHostingApplication(application, new HostOptions() { Watch = true }, async (app, uri) =>
var hostOptions = new HostOptions();
hostOptions.Watch.Add(ProcessRunnerOptions.AllServices);
await RunHostingApplication(application, hostOptions, async (app, uri) =>
{
// make sure both are running
var frontendUri = await GetServiceUrl(client, uri, "frontend");
@ -404,7 +406,10 @@ services:
var client = new HttpClient(new RetryHandler(handler));
await RunHostingApplication(application, new HostOptions() { Watch = true }, async (app, uri) =>
var hostOptions = new HostOptions();
hostOptions.Watch.Add(ProcessRunnerOptions.AllServices);
await RunHostingApplication(application, hostOptions, async (app, uri) =>
{
// make sure app is running
var appUri = await GetServiceUrl(client, uri, "web-app");

Loading…
Cancel
Save