diff --git a/AbpDevTools.csproj b/AbpDevTools.csproj index 8fb5008..c1b0024 100644 --- a/AbpDevTools.csproj +++ b/AbpDevTools.csproj @@ -2,7 +2,7 @@ Exe - 1.0.3 + 1.1.0 enable true abpdev diff --git a/Commands/RunCommand.cs b/Commands/RunCommand.cs index b14b740..7f9f75a 100644 --- a/Commands/RunCommand.cs +++ b/Commands/RunCommand.cs @@ -40,6 +40,9 @@ public class RunCommand : ICommand [CommandOption("env", 'e', Description = "Uses the virtual environment for this process. Use 'abpdev env config' command to see/manage environments.")] public string EnvironmentName { get; set; } + [CommandOption("retry", 'r', Description = "Retries running again when application exits.")] + public bool Retry { get; set; } + protected IConsole console; protected readonly List runningProjects = new(); @@ -190,7 +193,11 @@ await AnsiConsole.Live(table) while (!cancellationToken.IsCancellationRequested) { - await Task.Delay(1000); +#if DEBUG + await Task.Delay(100); +#else + await Task.Delay(500); +#endif table.Rows.Clear(); foreach (var project in runningProjects) @@ -201,9 +208,16 @@ await AnsiConsole.Live(table) } else { - if (project.Process.HasExited && !project.IsCompleted) + if (project.Process.HasExited && !project.Queued) { project.Status = $"[red]*[/] Exited({project.Process.ExitCode})"; + + if (Retry) + { + project.Status = $"[orange1]*[/] Exited({project.Process.ExitCode})"; + + _ = RestartProject(project); // fire and forget + } } table.AddRow(project.Name, project.Status); } @@ -214,6 +228,15 @@ await AnsiConsole.Live(table) }); } + private static async Task RestartProject(RunningProjectItem project) + { + project.Queued = true; + await Task.Delay(3100); + project.Status = $"[orange1]*[/] Exited({project.Process.ExitCode}) (Retrying...)"; + project.Process = Process.Start(project.Process.StartInfo); + project.StartReadingOutput(); + } + protected void KillRunningProcesses() { console.Output.WriteLine($"- Killing running {runningProjects.Count} processes..."); diff --git a/Commands/RunningProjectItem.cs b/Commands/RunningProjectItem.cs index 5e49d48..1e58fb1 100644 --- a/Commands/RunningProjectItem.cs +++ b/Commands/RunningProjectItem.cs @@ -8,6 +8,12 @@ public class RunningProjectItem public Process Process { get; set; } public virtual string Status { get; set; } public virtual bool IsCompleted { get; set; } + public virtual bool Queued { get; set; } + + public virtual void StartReadingOutput() + { + } + } public class RunningCsProjItem : RunningProjectItem @@ -17,14 +23,26 @@ public RunningCsProjItem(string name, Process process, string status = null) this.Name = name; this.Process = process; this.Status = status ?? "Building..."; + StartReadingOutput(); + } - process.OutputDataReceived += OutputReceived; - + public override void StartReadingOutput() + { + Queued = false; + Process.OutputDataReceived -= OutputReceived; + Process.OutputDataReceived += OutputReceived; Process.BeginOutputReadLine(); } protected virtual void OutputReceived(object sender, DataReceivedEventArgs args) { +#if DEBUG + if (!IsCompleted) + { + Status = args.Data?.Replace("[", string.Empty).Replace("]", string.Empty) ?? string.Empty; + } +#endif + if (args.Data != null && args.Data.Contains("Now listening on: ")) { Status = args.Data[args.Data.IndexOf("Now listening on: ")..]; @@ -32,8 +50,9 @@ protected virtual void OutputReceived(object sender, DataReceivedEventArgs args) IsCompleted = true; } - if (DateTime.Now - Process.StartTime > TimeSpan.FromMinutes(2)) + if (DateTime.Now - Process.StartTime > TimeSpan.FromMinutes(5)) { + Status = "Stale"; Process.OutputDataReceived -= OutputReceived; Process.CancelOutputRead(); } @@ -44,12 +63,17 @@ public class RunningInstallLibsItem : RunningProjectItem { public RunningInstallLibsItem(string name, Process process, string status = null) { - this.Name=name; + this.Name = name; this.Process = process; this.Status = status ?? "Installing..."; + StartReadingOutput(); + } - process.OutputDataReceived += OutputReceived; - process.BeginOutputReadLine(); + public override void StartReadingOutput() + { + Process.OutputDataReceived -= OutputReceived; + Process.OutputDataReceived += OutputReceived; + Process.BeginOutputReadLine(); } protected virtual void OutputReceived(object sender, DataReceivedEventArgs args) @@ -63,6 +87,7 @@ protected virtual void OutputReceived(object sender, DataReceivedEventArgs args) if (DateTime.Now - Process.StartTime > TimeSpan.FromMinutes(5)) { + Status = "Stale"; Process.OutputDataReceived -= OutputReceived; Process.CancelOutputRead(); }