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,6 +145,8 @@ namespace directors_assistant
}); });
}); });
try
{
stopwatch.Start(); stopwatch.Start();
process.Start(); process.Start();
process.BeginErrorReadLine(); process.BeginErrorReadLine();
@ -159,6 +161,17 @@ namespace directors_assistant
exit_code = process.ExitCode 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)
{ {