protected virtual async Task <bool> ShouldRetry(IMessage @event)
        {
            var retryData = await _messageQueueRepository.GetRetryData(@event).ConfigureAwait(false);

            // exponential backoff
            var mpow           = (int)Math.Pow(2, retryData.RetryCount);
            var interval       = Math.Min(mpow * RetryIntervalMinutes, RetryIntervalMaxMinutes);
            var intervalPassed = DateTimeOffset.UtcNow > retryData.LastRetryTime?.ToUniversalTime().AddMinutes(interval);

            if (!intervalPassed && retryData.RetryCount > 0)
            {
                LogInformation($"Skipping retry for event with Aggregate Id {@event.Id}; Retry interval has not elapsed.");
                return(false);
            }

            if (RetryForHours != default(int) &&
                DateTimeOffset.UtcNow < @event.TimeStamp.ToUniversalTime().AddHours(RetryForHours))
            {
                return(true);
            }

            if (retryData.RetryCount > RetryLimit)
            {
                LogInformation($"Skipping retry for event with Aggregate Id {@event.Id}; Retry threshold reached");
                return(false);
            }

            return(true);
        }
コード例 #2
0
        protected virtual async Task <bool> ShouldRetry(IMessage @event, RedisValue eventData)
        {
            var retryData = await _messageQueueRepository.GetRetryData(@event).ConfigureAwait(false);

            // exponential backoff
            var mpow           = Math.Pow(2, retryData.RetryCount);
            var interval       = Math.Min(mpow * RetryIntervalMinutes, RetryIntervalMaxMinutes);
            var intervalPassed = DateTimeOffset.UtcNow > retryData.LastRetryTime?.ToUniversalTime().AddMinutes(interval);

            if (!intervalPassed && retryData.RetryCount > 0)
            {
                _logger.Debug($"Skipping retry for event with Aggregate Id {@event.Id}; Retry interval has not elapsed.");
                return(false);
            }

            if (TimeToLiveHours != default(int) &&
                DateTimeOffset.UtcNow > @event.TimeStamp.ToUniversalTime().AddHours(TimeToLiveHours))
            {
                _logger.Debug($"Time to live of {TimeToLiveHours} hours exceeded for event with Aggregate Id {@event.Id}; Deleting from the dead letter queue.");
                await _messageQueueRepository.DeleteFromDeadLetterQueue <T>(eventData, @event).ConfigureAwait(false);

                return(false);
            }

            return(true);
        }