Compare commits

...

4 Commits

  1. 5
      src/Microsoft.Tye.Hosting/Model/Application.cs
  2. 21
      src/Microsoft.Tye.Hosting/ProcessRunner.cs
  3. 5
      src/Microsoft.Tye.Hosting/Watch/DotNetWatcher.cs

5
src/Microsoft.Tye.Hosting/Model/Application.cs

@ -3,10 +3,12 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace Microsoft.Tye.Hosting.Model
{
@ -25,6 +27,9 @@ namespace Microsoft.Tye.Hosting.Model
public Dictionary<string, Service> Services { get; }
internal ConcurrentDictionary<string, TaskCompletionSource<ProcessResult>> OngoingBuildProjectProcesses { get; }
= new ConcurrentDictionary<string, TaskCompletionSource<ProcessResult>>();
public Dictionary<object, object> Items { get; } = new Dictionary<object, object>();
public string? Network { get; set; }

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

@ -359,9 +359,28 @@ namespace Microsoft.Tye.Hosting
},
Build = async () =>
{
if (service.Description.RunInfo is ProjectRunInfo)
if (service.Description.RunInfo is ProjectRunInfo projectRunInfo)
{
var projectFile = projectRunInfo.ProjectFile.FullName;
var newProcess = new TaskCompletionSource<ProcessResult>();
var ongoingProcess = application.OngoingBuildProjectProcesses.GetOrAdd(projectFile, newProcess);
if (ongoingProcess != newProcess)
{
_logger.LogDebug($"[{replica}] A build has already been triggered for project {projectFile}");
return (await ongoingProcess.Task).ExitCode;
}
_logger.LogDebug($"[{replica}] Building project {projectFile}");
var buildResult = await ProcessUtil.RunAsync("dotnet", $"build \"{service.Status.ProjectFilePath}\" /nologo", throwOnError: false, workingDirectory: application.ContextDirectory);
_logger.LogDebug($"[{replica}] Finished Building project {projectFile}");
ongoingProcess.SetResult(buildResult);
// Cannot remove a specific KVP until net5.0. Workaround is to cast to ICollection<KVP<>>
ICollection<KeyValuePair<string, TaskCompletionSource<ProcessResult>>> projectProcesses = application.OngoingBuildProjectProcesses;
projectProcesses.Remove(KeyValuePair.Create(projectFile, ongoingProcess));
if (buildResult.ExitCode != 0)
{
_logger.LogInformation("Building projects failed with exit code {ExitCode}: \r\n" + buildResult.StandardOutput, buildResult.ExitCode);

5
src/Microsoft.Tye.Hosting/Watch/DotNetWatcher.cs

@ -88,7 +88,7 @@ namespace Microsoft.DotNet.Watcher
if (finishedTask == processTask)
{
// Now wait for a file to change before restarting process
await fileSetWatcher.GetChangedFileAsync(cancellationToken, () => _logger.LogWarning("Waiting for a file to change before restarting dotnet..."));
await fileSetWatcher.GetChangedFileAsync(cancellationToken, () => _logger.LogWarning("watch: {Replica} Waiting for a file to change before restarting dotnet...", replica));
}
if (!string.IsNullOrEmpty(fileSetTask.Result))
@ -112,7 +112,8 @@ namespace Microsoft.DotNet.Watcher
// Build failed, keep retrying builds until successful build.
}
await fileSetWatcher.GetChangedFileAsync(cancellationToken, () => _logger.LogWarning("Waiting for a file to change before restarting dotnet..."));
// Now wait for a file to change before restarting process
await fileSetWatcher.GetChangedFileAsync(cancellationToken, () => _logger.LogWarning("watch: {Replica} Waiting for a file to change before restarting dotnet...", replica));
}
}
}

Loading…
Cancel
Save