Exemplo n.º 1
0
        public async Task <bool> HandleAsync(PackageValidationMessageData message)
        {
            if (_shutdownNotificationTokenProvider.Token.IsCancellationRequested)
            {
                _logger.LogInformation("Service shutdown was requested, will not process new message");
                return(false);
            }

            var package = _galleryPackageService.FindPackageByIdAndVersionStrict(message.PackageId, message.PackageVersion);

            if (package == null)
            {
                // no package in DB yet. Might have received message a bit early, need to retry later
                _logger.LogInformation("Did not find information in DB for package {PackageId} {PackageVersion}",
                                       message.PackageId,
                                       message.PackageVersion);
                return(false);
            }

            using (_logger.BeginScope("Handling message for {PackageId} {PackageVersion} validation set {ValidationSetId}", message.PackageId, message.PackageVersion, message.ValidationTrackingId))
            {
                var validationSet = await _validationSetProvider.GetOrCreateValidationSetAsync(message.ValidationTrackingId, package);

                await _validationSetProcessor.ProcessValidationsAsync(validationSet, package);

                await _validationOutcomeProcessor.ProcessValidationOutcomeAsync(validationSet, package);
            }
            return(true);
        }
Exemplo n.º 2
0
        public async Task <bool> HandleAsync(PackageValidationMessageData message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            using (_logger.BeginScope("Handling message for {PackageId} {PackageVersion} validation set {ValidationSetId}",
                                      message.PackageId,
                                      message.PackageVersion,
                                      message.ValidationTrackingId))
            {
                var package = _galleryPackageService.FindPackageByIdAndVersionStrict(message.PackageId, message.PackageVersion);

                if (package == null)
                {
                    // no package in DB yet. Might have received message a bit early, need to retry later
                    if (message.DeliveryCount - 1 >= _configs.MissingPackageRetryCount)
                    {
                        _logger.LogWarning("Could not find package {PackageId} {PackageVersion} in DB after {DeliveryCount} tries, dropping message",
                                           message.PackageId,
                                           message.PackageVersion,
                                           message.DeliveryCount);

                        _telemetryService.TrackMissingPackageForValidationMessage(
                            message.PackageId,
                            message.PackageVersion,
                            message.ValidationTrackingId.ToString());

                        return(true);
                    }
                    else
                    {
                        _logger.LogInformation("Could not find package {PackageId} {PackageVersion} in DB, retrying",
                                               message.PackageId,
                                               message.PackageVersion);

                        return(false);
                    }
                }

                // Immediately halt validation of a soft deleted package.
                if (package.PackageStatusKey == PackageStatus.Deleted)
                {
                    _logger.LogWarning(
                        "Package {PackageId} {PackageVersion} (package key {PackageKey}) is soft deleted. Dropping message for validation set {ValidationSetId}.",
                        message.PackageId,
                        message.PackageVersion,
                        package.Key,
                        message.ValidationTrackingId);

                    return(true);
                }

                var validationSet = await _validationSetProvider.TryGetOrCreateValidationSetAsync(message.ValidationTrackingId, package);

                if (validationSet == null)
                {
                    _logger.LogInformation("The validation request for {PackageId} {PackageVersion} validation set {ValidationSetId} is a duplicate. Discarding.",
                                           message.PackageId,
                                           message.PackageVersion,
                                           message.ValidationTrackingId);
                    return(true);
                }

                await _validationSetProcessor.ProcessValidationsAsync(validationSet, package);

                await _validationOutcomeProcessor.ProcessValidationOutcomeAsync(validationSet, package);
            }
            return(true);
        }
        public async Task <bool> HandleAsync(PackageValidationMessageData message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            using (_logger.BeginScope("Handling symbol message for {PackageId} {PackageVersion} validation set {ValidationSetId}",
                                      message.PackageId,
                                      message.PackageNormalizedVersion,
                                      message.ValidationTrackingId))
            {
                // When a message is sent from the Gallery with validation of a new entity, the EntityKey will be null because the message is sent to the service bus before the entity is persisted in the DB
                // However when a revalidation happens or when the message is re-sent by the orchestrator the message will contain the key. In this case the key is used to find the entity to validate.
                var symbolPackageEntity = message.EntityKey.HasValue
                    ? _gallerySymbolService.FindPackageByKey(message.EntityKey.Value)
                    : _gallerySymbolService.FindPackageByIdAndVersionStrict(message.PackageId, message.PackageNormalizedVersion);

                if (symbolPackageEntity == null)
                {
                    // no package in DB yet. Might have received message a bit early, need to retry later
                    if (message.DeliveryCount - 1 >= _configs.MissingPackageRetryCount)
                    {
                        _logger.LogWarning("Could not find symbols for package {PackageId} {PackageNormalizedVersion} in DB after {DeliveryCount} tries, dropping message",
                                           message.PackageId,
                                           message.PackageNormalizedVersion,
                                           message.DeliveryCount);

                        _telemetryService.TrackMissingPackageForValidationMessage(
                            message.PackageId,
                            message.PackageNormalizedVersion,
                            message.ValidationTrackingId.ToString());

                        return(true);
                    }
                    else
                    {
                        _logger.LogInformation("Could not find symbols for package {PackageId} {PackageNormalizedVersion} {Key} in DB, retrying",
                                               message.PackageId,
                                               message.PackageNormalizedVersion,
                                               message.EntityKey.HasValue);

                        return(false);
                    }
                }

                var validationSet = await _validationSetProvider.TryGetOrCreateValidationSetAsync(message, symbolPackageEntity);

                if (validationSet == null)
                {
                    _logger.LogInformation(
                        "The validation request for {PackageId} {PackageNormalizedVersion} validation set " +
                        "{ValidationSetId} is a duplicate. Discarding the message.",
                        message.PackageId,
                        message.PackageNormalizedVersion,
                        message.ValidationTrackingId);
                    return(true);
                }

                if (validationSet.ValidationSetStatus == ValidationSetStatus.Completed)
                {
                    _logger.LogInformation(
                        "The validation set {PackageId} {PackageNormalizedVersion} {ValidationSetId} is already " +
                        "completed. Discarding the message.",
                        message.PackageId,
                        message.PackageNormalizedVersion,
                        message.ValidationTrackingId);
                    return(true);
                }

                var processorStats = await _validationSetProcessor.ProcessValidationsAsync(validationSet);

                // As part of the processing the validation outcome the orchestrator will send itself a message if validation are still being processed.
                await _validationOutcomeProcessor.ProcessValidationOutcomeAsync(validationSet, symbolPackageEntity, processorStats);
            }

            return(true);
        }