Beispiel #1
0
        public async Task InitializeAsync()
        {
            if (await _jobState.IsInitializedAsync())
            {
                _logger.LogError("Attempted to initialize the revalidation job when it is already initialized!");

                throw new InvalidOperationException("Attempted to initialize the revalidation job when it is already initialized!");
            }

            await ClearPackageRevalidationStateAsync();

            // Find packages owned by Microsoft or preinstalled by Visual Studio.
            var microsoftPackages    = _packageFinder.FindMicrosoftPackages();
            var preinstalledPackages = _packageFinder.FindPreinstalledPackages(except: microsoftPackages);

            // Find the packages depended by both Microsoft and preinstalled packages.
            var microsoftOrPreinstalledPackages = new HashSet <int>();

            microsoftOrPreinstalledPackages.UnionWith(microsoftPackages);
            microsoftOrPreinstalledPackages.UnionWith(preinstalledPackages);

            var dependencyPackages = _packageFinder.FindDependencyPackages(microsoftOrPreinstalledPackages);

            // Find the set of all other packages.
            var knownPackages = new HashSet <int>();

            knownPackages.UnionWith(microsoftOrPreinstalledPackages);
            knownPackages.UnionWith(dependencyPackages);

            var remainingPackages = _packageFinder.FindAllPackages(except: knownPackages);

            // Save the packages that were found, by order of priority.
            await InitializePackageSetAsync(PackageFinder.MicrosoftSetName, microsoftPackages);
            await InitializePackageSetAsync(PackageFinder.PreinstalledSetName, preinstalledPackages);
            await InitializePackageSetAsync(PackageFinder.DependencySetName, dependencyPackages);
            await InitializePackageSetAsync(PackageFinder.RemainingSetName, remainingPackages);

            await _jobState.MarkAsInitializedAsync();
        }
        public async Task RunAsync()
        {
            if (!await _jobState.IsInitializedAsync())
            {
                _logger.LogError("The revalidation service must be initialized before running revalidations");

                throw new InvalidOperationException("The revalidation service must be initialized before running revalidations");
            }

            var runTime = Stopwatch.StartNew();

            do
            {
                _logger.LogInformation("Starting next revalidation...");

                var startRevalidationsStopwatch = Stopwatch.StartNew();
                var result = await StartNextRevalidationsAsync();

                startRevalidationsStopwatch.Stop();

                switch (result.Status)
                {
                case StartRevalidationStatus.RevalidationsEnqueued:
                    _logger.LogInformation(
                        "Successfully enqueued {RevalidationsStarted} revalidations in {Duration}",
                        result.RevalidationsStarted,
                        startRevalidationsStopwatch.Elapsed);

                    await _throttler.DelayUntilNextRevalidationAsync(result.RevalidationsStarted, startRevalidationsStopwatch.Elapsed);

                    break;

                case StartRevalidationStatus.RetryLater:
                    _logger.LogInformation("Could not start revalidation, retrying later");

                    await _throttler.DelayUntilRevalidationRetryAsync();

                    break;

                case StartRevalidationStatus.UnrecoverableError:
                default:
                    _logger.LogCritical(
                        "Stopping revalidations due to unrecoverable or unknown result {Result}",
                        result);

                    return;
                }
            }while (runTime.Elapsed <= _config.ShutdownWaitInterval);

            _logger.LogInformation("Finished running after {ElapsedTime}", runTime.Elapsed);
        }