public async Task <StartRevalidationResult> StartNextRevalidationsAsync()
        {
            try
            {
                // Don't start a revalidation if the job has been deactivated, if the ingestion pipeline is unhealthy,
                // or if we have reached our quota of desired revalidations.
                var checkResult = await CanStartRevalidationAsync();

                if (checkResult != null)
                {
                    _logger.LogInformation(
                        "Detected that a revalidation should not be started due to result {Result}",
                        checkResult.Value);

                    switch (checkResult.Value)
                    {
                    case StartRevalidationStatus.RetryLater:
                        return(StartRevalidationResult.RetryLater);

                    case StartRevalidationStatus.UnrecoverableError:
                        return(StartRevalidationResult.UnrecoverableError);

                    default:
                        throw new InvalidOperationException($"Unexpected status {checkResult.Value} from {nameof(CanStartRevalidationAsync)}");
                    }
                }

                // Everything is in tip-top shape! Increase the throttling quota and start the next revalidations.
                await _jobState.IncreaseDesiredPackageEventRateAsync();

                var revalidations = await _revalidationQueue.NextAsync();

                if (!revalidations.Any())
                {
                    _logger.LogInformation("Could not find packages to revalidate at this time, retry later...");

                    return(StartRevalidationResult.RetryLater);
                }

                return(await StartRevalidationsAsync(revalidations));
            }
            catch (Exception e)
            {
                _logger.LogError(0, e, "Failed to start next validation due to exception, retry later...");

                return(StartRevalidationResult.RetryLater);
            }
        }
Beispiel #2
0
        public async Task <RevalidationResult> StartNextRevalidationAsync()
        {
            try
            {
                // Don't start a revalidation if the job has been deactivated, if the ingestion pipeline is unhealthy,
                // or if we have reached our quota of desired revalidations.
                var checkResult = await CanStartRevalidationAsync();

                if (checkResult != null)
                {
                    _logger.LogInformation(
                        "Detected that a revalidation should not be started due to result {Result}",
                        checkResult.Value);

                    return(checkResult.Value);
                }

                // Everything is in tip-top shape! Increase the throttling quota and start the next revalidation.
                await _jobState.IncreaseDesiredPackageEventRateAsync();

                var revalidation = await _revalidationQueue.NextOrNullAsync();

                if (revalidation == null)
                {
                    _logger.LogInformation("Could not find a package to revalidate at this time, retry later...");

                    return(RevalidationResult.RetryLater);
                }

                return(await StartRevalidationAsync(revalidation));
            }
            catch (Exception e)
            {
                _logger.LogError(0, e, "Failed to start next validation due to exception, retry later...");

                return(RevalidationResult.RetryLater);
            }
        }