more resilient

This commit is contained in:
Adam R. Grey 2021-10-26 07:33:39 -04:00
parent d9e875ed10
commit 43bcc27137

View File

@ -39,7 +39,7 @@ namespace directors_assistant
justArgs.AddRange(ec.args); justArgs.AddRange(ec.args);
var commandPath = cmdAndArgs[0]; var commandPath = cmdAndArgs[0];
var commandArguments = String.Join(' ', justArgs); 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); executeTimed(cmd.name, commandPath, commandArguments, ec.timeout);
} }
@ -72,7 +72,7 @@ namespace directors_assistant
process.Start(); process.Start();
process.BeginErrorReadLine(); process.BeginErrorReadLine();
process.BeginOutputReadLine(); process.BeginOutputReadLine();
if (timeout > TimeSpan.Zero) if (timeout != null && timeout > TimeSpan.Zero)
{ {
Task.WaitAny( Task.WaitAny(
Task.Run(() => Task.Run(() =>
@ -145,19 +145,32 @@ namespace directors_assistant
}); });
}); });
stopwatch.Start(); try
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, stopwatch.Start();
runtimeMilliseconds = stopwatch.ElapsedMilliseconds, process.Start();
exit_code = process.ExitCode 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) private static Process readableProcess(string commandPath, string commandArguments)