Exemplo n.º 1
0
        private void DisplayGroupStats(ProcessState state)
        {
            var percentage = (float)state.Config.Processed.Count / (float)state.Config.TotalItems * 100f;

            Console.WriteLine($">> {state.Config.Processed.Count}/{state.Config.TotalItems}. ({percentage:0}%) Time: {state.Average.CurrentAverage().FormatForDisplay(true)}");

            var estimatedRemaining = new TimeSpan(state.Average.CurrentAverage().Ticks *state.Config.Items.Count);

            if (state.Config.Processed.Count != state.Config.TotalItems)
            {
                Console.WriteLine($@">> Estimated remaining: {estimatedRemaining.FormatForDisplay(true)} - ending {DateTime.Now + estimatedRemaining}");
            }
        }
Exemplo n.º 2
0
        private void ProcessAllGroups(ProcessState state)
        {
            Console.CancelKeyPress += CancelHandler;

            while (state.Config.Items.Count > 0 && !_cancelTriggered)
            {
                ProcessGroup(state);

                DisplayGroupStats(state);

                if (state.Config.Items.Count > 0 && !_cancelTriggered)
                {
                    BackupAndVerifyDiskSpace(state);
                }
            }

            Console.CancelKeyPress -= CancelHandler;
        }
Exemplo n.º 3
0
        public override void Run()
        {
            base.OverrideFileType(_options.ConfigFile);
            base.Run();

            Console.WriteLine("Running indexing");
            Console.WriteLine("----------------");

            var config = _configFileManager.Load(_options.ConfigFile);

            if (config == null)
            {
                Console.WriteLine($">> Error: Config file '{_configFileManager.VerifyFilename(_options.ConfigFile)}' not found");
                return;
            }

            if (config.Processed.Count == config.TotalItems)
            {
                Console.WriteLine($">> No items to process.");
                return;
            }

            ISitecoreEndpoint endPoint = _endpointFactory.Create(config.Url);
            var state = new ProcessState(endPoint, _options, config);

            state.Config.Attempts += 1;
            var startedAt = DateTime.Now;

            SetTimeout(state);

            ProcessAllGroups(state);

            var endedAt = DateTime.Now;
            var elapsed = endedAt - startedAt;

            state.Config.Elapsed += elapsed;

            SaveState(state);

            Console.WriteLine($">> Finished");
            Console.WriteLine($">>   at {endedAt} - after {elapsed.FormatForDisplay()}");
            Console.WriteLine($">>   with {state.Config.Errors.Count()} errors");
            Console.WriteLine($">>   total time now {state.Config.Elapsed.FormatForDisplay()} after {state.Config.Attempts} attempts.");
        }
Exemplo n.º 4
0
        private void BackupAndVerifyDiskSpace(ProcessState state)
        {
            var filename = _configFileManager.RuntimeBackupFilename(state.Options.ConfigFile);

            Console.WriteLine(">> Saving runtime backup");
            _configFileManager.Save(filename, state.Config);

            var saveSize = _configFileManager.SizeOfSave(filename);

            saveSize = saveSize + (saveSize / 4); // 1.25 times is a safety margin

            var path  = System.IO.Path.GetFullPath(filename);
            var drive = new System.IO.DriveInfo(path);

            if (drive.AvailableFreeSpace < saveSize)
            {
                Console.WriteLine(">> There is no longer sufficient free disk space to save safely. Aborting.");
                _cancelTriggered = true;
            }
        }
Exemplo n.º 5
0
 private void SetTimeout(ProcessState state)
 {
     if (state.Options.Timeout < 0)
     {
         if (state.Config.Timeout > 0)
         {
             state.Options.Timeout = state.Config.Timeout;
             Console.WriteLine($">> Using timeout setting from config file: {state.Options.Timeout}s");
         }
         else
         {
             state.Options.Timeout = 60;
             Console.WriteLine($">> No timeout settings found. Using default: {state.Options.Timeout}s");
         }
     }
     else
     {
         Console.WriteLine($">> Using timeout setting from command line: {state.Options.Timeout}s");
     }
 }
Exemplo n.º 6
0
        private bool ProcessItem(ProcessState state, ItemEntry itm)
        {
            bool result;

            try
            {
                Console.Write($"{itm.Id} {itm.Name}...");

                var indexResult = state.Endpoint.IndexItem(state.Config.Token, itm, state.Config.Database, state.Config.Indexes, state.Options.Timeout);
                result = !indexResult.Error;

                if (indexResult.Error)
                {
                    var err = new ItemFailure()
                    {
                        At          = DateTime.Now,
                        Item        = itm,
                        Errors      = indexResult.Activities.Select(a => a.Error).ToArray(),
                        FailureType = FailureType.Warning
                    };
                    state.Config.Errors.Enqueue(err);
                }
            }
            catch (Exception ex)
            {
                result = false;
                var err = new ItemFailure()
                {
                    At          = DateTime.Now,
                    Item        = itm,
                    Errors      = new string[] { formatException(ex) },
                    FailureType = FailureType.Warning
                };
                state.Config.Errors.Enqueue(err);
            }

            return(result);
        }
Exemplo n.º 7
0
        private void HandleResult(bool result, ProcessState state, ItemEntry itm, ref int retries, ref int processed)
        {
            if (result == false)
            {
                if (retries == state.Options.Retries)
                {
                    retries    = 0;
                    processed += 1;
                    state.Config.Processed.Enqueue(state.Config.Items.Dequeue());

                    state.Config.Errors.Enqueue(new ItemFailure()
                    {
                        At = DateTime.Now, Item = itm, Errors = new string[] { "Too many retries - aborting" }, FailureType = FailureType.Error
                    });
                    Console.WriteLine($"\r{itm.Id} {itm.Name} -- {state.sw.Elapsed.FormatForDisplay(true)} -- Too many retries");
                }
                else
                {
                    retries += 1;
                    Console.WriteLine($"\r{itm.Id} {itm.Name} -- {state.sw.Elapsed.FormatForDisplay(true)} -- Warning #{retries}");
                    RandomBackOff(retries);
                }
            }
            else
            {
                var msg = string.Empty;
                if (retries > 0)
                {
                    msg = " - Transient error corrected";
                }

                Console.WriteLine($"\r{itm.Id} {itm.Name} -- {state.sw.Elapsed.FormatForDisplay(true)}{msg}");
                state.Config.Processed.Enqueue(state.Config.Items.Dequeue());
                processed += 1;
                retries    = 0;
            }
        }