/// <summary> /// Times out the current thread and retries <see cref="CreateAndPullUpBootstraps()"/> after the timeout is complete. /// </summary> private static void TimeoutAndRetryPullUp() { if (bootstraps != null) { bootstraps.Dispose(); bootstraps = null; } if (pullUpFailCount < 10) { logger.Info(CultureInfo.InvariantCulture, "Trying again in 10 seconds ({0} of 10).", pullUpFailCount); Thread.Sleep(10000); CreateAndPullUpBootstraps(); } else { logger.Fatal("I'm giving up."); if (inputThread != null && inputThread.IsAlive) { inputThread.Abort(); } if (exitHandle != null) { exitHandle.Set(); } } }
private static void CreateAndPullUpBootstraps() { lock (bootstrapsLocker) { if (bootstraps != null) { bootstraps.Dispose(); bootstraps = null; } try { bootstraps = new JobRunnerBootstraps(directory, config, persistencePath, fileSystemWatcherThreshold); bootstraps.AllFinished += new EventHandler(BootstrapsAllFinished); bootstraps.CancelJob += new EventHandler<JobRecordEventArgs>(BootstrapsCancelJob); bootstraps.ChangeDetected += new EventHandler<FileSystemEventArgs>(BootstrapsChangeDetected); bootstraps.DequeueJob += new EventHandler<JobRecordEventArgs>(BootstrapsDequeueJob); bootstraps.Error += new EventHandler<JobErrorEventArgs>(BootstrapsError); bootstraps.ExecuteScheduledJob += new EventHandler<JobRecordEventArgs>(BootstrapsExecuteScheduledJob); bootstraps.FinishJob += new EventHandler<JobRecordEventArgs>(BootstrapsFinishJob); bootstraps.RetryEnqueued += new EventHandler<JobRecordEventArgs>(BootstrapsRetryEnqueued); bootstraps.TimeoutJob += new EventHandler<JobRecordEventArgs>(BootstrapsTimeoutJob); bootstraps.PullUp(); pullUpFailCount = 0; string info = String.Format(CultureInfo.InvariantCulture, "The job runner is active at '{0}'", bootstraps.BasePath); if (!String.IsNullOrEmpty(bootstraps.ConfigurationFilePath)) { info += String.Format(CultureInfo.InvariantCulture, ", using the configuration file at '{0}'.", bootstraps.ConfigurationFilePath); } logger.Info(info); logger.Info("Press Q+Enter to safely shut down or Ctl+C to exit immediately."); } catch (Exception ex) { pullUpFailCount++; logger.Error(CultureInfo.InvariantCulture, "Failed to bootstrap a job runner at the destination with the message: {0}", ex.Message); logger.Error(ex.StackTrace); TimeoutAndRetryPullUp(); } } }