From 43bcc271374a11de75c0dd94732ddfcb534eb042 Mon Sep 17 00:00:00 2001 From: "Adam R. Grey" Date: Tue, 26 Oct 2021 07:33:39 -0400 Subject: [PATCH] more resilient --- Program.cs | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/Program.cs b/Program.cs index 88a7f69..5883c8e 100644 --- a/Program.cs +++ b/Program.cs @@ -39,7 +39,7 @@ namespace directors_assistant justArgs.AddRange(ec.args); var commandPath = cmdAndArgs[0]; var commandArguments = String.Join(' ', justArgs); - if (ec.timeout > TimeSpan.Zero) + if (ec.timeout != null && ec.timeout > TimeSpan.Zero) { executeTimed(cmd.name, commandPath, commandArguments, ec.timeout); } @@ -72,7 +72,7 @@ namespace directors_assistant process.Start(); process.BeginErrorReadLine(); process.BeginOutputReadLine(); - if (timeout > TimeSpan.Zero) + if (timeout != null && timeout > TimeSpan.Zero) { Task.WaitAny( Task.Run(() => @@ -145,19 +145,32 @@ namespace directors_assistant }); }); - stopwatch.Start(); - process.Start(); - process.BeginErrorReadLine(); - process.BeginOutputReadLine(); - process.WaitForExit(); - stopwatch.Stop(); - Console.WriteLine($"{commandName} returned {process.ExitCode} after {stopwatch.ElapsedMilliseconds}ms"); - telefranz.ProduceMessage(new silver_messages.directorial.command_completed() + try { - command = commandName, - runtimeMilliseconds = stopwatch.ElapsedMilliseconds, - exit_code = process.ExitCode - }); + stopwatch.Start(); + process.Start(); + process.BeginErrorReadLine(); + process.BeginOutputReadLine(); + process.WaitForExit(); + stopwatch.Stop(); + Console.WriteLine($"{commandName} returned {process.ExitCode} after {stopwatch.ElapsedMilliseconds}ms"); + telefranz.ProduceMessage(new silver_messages.directorial.command_completed() + { + command = commandName, + runtimeMilliseconds = stopwatch.ElapsedMilliseconds, + exit_code = process.ExitCode + }); + } + catch(Exception e) + { + Console.Error.WriteLine($"{commandName} FATAL: {JsonConvert.SerializeObject(e)}"); + telefranz.ProduceMessage(new silver_messages.directorial.command_error() + { + stderr = e.Message, + command = commandName, + runtime = (uint)stopwatch.ElapsedMilliseconds + }); + } } private static Process readableProcess(string commandPath, string commandArguments)