public void RunApplication(string[] args) { var cmdLine = new CmdLine(); try { cmdLine.Parse(args); } catch (Exception e) { Platform.Log(LogLevel.Info, e); Console.WriteLine(e.Message); cmdLine.PrintUsage(Console.Out); Environment.Exit(-1); } int timeoutMillisecondsRemaining = cmdLine.Timeout * 1000; int tryCount = 0; while (timeoutMillisecondsRemaining > 0) { ++tryCount; if (tryCount > 1) { Platform.Log(LogLevel.Info, "Previous attempt to start re-index failed - trying again (attempt #{0})", tryCount); Console.WriteLine("Previous attempt to start re-index failed - trying again (attempt #{0})", tryCount); } int startTicks = Environment.TickCount; try { var client = new ReindexFilestoreBridge(); client.Reindex(); Console.WriteLine("The re-index has been scheduled."); Environment.ExitCode = 0; return; } catch (EndpointNotFoundException) { Platform.Log(LogLevel.Warn, "Failed to start re-index because the Work Item service isn't running."); } catch (Exception e) { Platform.Log(LogLevel.Error, e, "Failed to start re-index."); Console.WriteLine("Failed to start re-index."); } finally { Thread.Sleep(2000); var elapsedMilliseconds = Environment.TickCount - startTicks; timeoutMillisecondsRemaining -= elapsedMilliseconds; } } Platform.Log(LogLevel.Warn, "Unable to start re-index after {0} attempts", tryCount); Console.WriteLine("Unable to start re-index after {0} attempts", tryCount); Environment.ExitCode = -1; }
public void RunApplication(string[] args) { var cmdLine = new CmdLine(); try { cmdLine.Parse(args); } catch (Exception e) { Platform.Log(LogLevel.Info, e); Console.WriteLine(e.Message); cmdLine.PrintUsage(Console.Out); Environment.Exit(-1); } int timeoutMillisecondsRemaining = cmdLine.Timeout*1000; int tryCount = 0; while (timeoutMillisecondsRemaining > 0) { ++tryCount; if (tryCount > 1) { Platform.Log(LogLevel.Info, "Previous attempt to start re-index failed - trying again (attempt #{0})", tryCount); Console.WriteLine("Previous attempt to start re-index failed - trying again (attempt #{0})", tryCount); } int startTicks = Environment.TickCount; try { var client = new ReindexFilestoreBridge(); client.Reindex(); Console.WriteLine("The re-index has been scheduled."); Environment.ExitCode = 0; return; } catch (EndpointNotFoundException) { Platform.Log(LogLevel.Warn, "Failed to start re-index because the Work Item service isn't running."); } catch (Exception e) { Platform.Log(LogLevel.Error, e, "Failed to start re-index."); Console.WriteLine("Failed to start re-index."); } finally { Thread.Sleep(2000); var elapsedMilliseconds = Environment.TickCount - startTicks; timeoutMillisecondsRemaining -= elapsedMilliseconds; } } Platform.Log(LogLevel.Warn, "Unable to start re-index after {0} attempts", tryCount); Console.WriteLine("Unable to start re-index after {0} attempts", tryCount); Environment.ExitCode = -1; }