protected override void OnStart()
            {
                var fileNamesWithoutExtension = Directory.GetFiles(directory, "*.upgrade").Select(Path.GetFileNameWithoutExtension);

                var latestUpgrade = new List <long>();

                foreach (var fileNameWithoutExtension in fileNamesWithoutExtension)
                {
                    long upgradeTime;
                    if (long.TryParse(fileNameWithoutExtension, out upgradeTime))
                    {
                        latestUpgrade.Add(upgradeTime);
                    }
                }

                if (latestUpgrade.Count == 0)
                {
                    return;
                }

                latestUpgrade.Sort();    // ascending
                latestUpgrade.Reverse(); // descending

                tokenSource = new CancellationTokenSource();
                var fileTime = latestUpgrade[0];
                var latest   = DateTime.FromFileTimeUtc(fileTime);

                // File exists, so assume in progress
                staleIndexInfoStore.Store(new StaleIndexInfo {
                    InProgress = true, StartedAt = latest
                });

                checkTask = Task.Run(async() =>
                {
                    while (!tokenSource.IsCancellationRequested)
                    {
                        if (!await staleIndexChecker.IsReindexingInComplete(latest, tokenSource.Token).ConfigureAwait(false))
                        {
                            continue;
                        }

                        try
                        {
                            File.Delete(Path.Combine(directory, $"{fileTime}.upgrade"));
                        }
                        catch (IOException)
                        {
                            // if we can't delete for now that is OK
                        }
                        staleIndexInfoStore.Store(StaleIndexInfoStore.NotInProgress);
                        break;
                    }
                });
            }