コード例 #1
0
        private async Task <bool> SaveStatusAsync(ValidatorStatus validation, SignatureValidationMessage message)
        {
            try
            {
                var saveStatus = await _validatorStateService.SaveStatusAsync(validation);

                if (saveStatus == SaveStatusResult.Success)
                {
                    // Consume the message.
                    return(true);
                }
                else
                {
                    _logger.LogWarning(
                        "Unable to save to save due to stale context, requeueing package {PackageId} {PackageVersion} for validation id: {ValidationId}.",
                        message.PackageId,
                        message.PackageVersion,
                        message.ValidationId);
                }
            }
            catch (DbUpdateException e) when(e.IsUniqueConstraintViolationException())
            {
                _logger.LogWarning(
                    0,
                    e,
                    "Unable to save to save due to unique contrainst violation, requeueing package {PackageId} {PackageVersion} for validation id: {ValidationId}.",
                    message.PackageId,
                    message.PackageVersion,
                    message.ValidationId);
            }

            // Message may be retried.
            return(false);
        }
コード例 #2
0
        private async Task <bool> SaveStatusAsync(ValidatorStatus validation, SymbolsValidatorMessage message, int maxRetries)
        {
            bool saveStatus   = false;
            int  currentRetry = 0;

            while (!saveStatus && ++currentRetry < maxRetries)
            {
                try
                {
                    _logger.LogWarning(
                        "{ValidatorName}:Try to save validation status package {PackageId} {PackageVersion} for validation id: {ValidationId} RetryCount: {currentRetry}.",
                        ValidatorName.SymbolsValidator,
                        message.PackageId,
                        message.PackageNormalizedVersion,
                        message.ValidationId,
                        currentRetry);
                    saveStatus = await _validatorStateService.SaveStatusAsync(validation) == SaveStatusResult.Success;
                }
                catch (Exception e)
                {
                    _logger.LogWarning(
                        0,
                        e,
                        "{ValidatorName}:Unable to save to save package {PackageId} {PackageVersion} for validation id: {ValidationId}.",
                        ValidatorName.SymbolsValidator,
                        message.PackageId,
                        message.PackageNormalizedVersion,
                        message.ValidationId);
                }
            }
            if (!saveStatus)
            {
                _logger.LogWarning(
                    "{ValidatorName}:Unable to save to save after {MaxRetries}. Requeueing package {PackageId} {PackageVersion} for validation id: {ValidationId}.",
                    ValidatorName.SymbolsValidator,
                    maxRetries,
                    message.PackageId,
                    message.PackageNormalizedVersion,
                    message.ValidationId);
            }
            return(saveStatus);
        }