Ejemplo n.º 1
0
        private async Task StageRetryByUniqueMessageIds(string requestId, RetryType retryType, string[] messageIds, DateTime startTime, DateTime?last = null, string originator = null, string batchName = null, string classifier = null)
        {
            if (messageIds == null || !messageIds.Any())
            {
                log.DebugFormat("Batch '{0}' contains no messages", batchName);
                return;
            }

            var failedMessageRetryIds = messageIds.Select(FailedMessageRetry.MakeDocumentId).ToArray();

            var batchDocumentId = await retryDocumentManager.CreateBatchDocument(requestId, retryType, failedMessageRetryIds, originator, startTime, last, batchName, classifier)
                                  .ConfigureAwait(false);

            log.InfoFormat("Created Batch '{0}' with {1} messages for '{2}'", batchDocumentId, messageIds.Length, batchName);

            var commands = new ICommandData[messageIds.Length];

            for (var i = 0; i < messageIds.Length; i++)
            {
                commands[i] = retryDocumentManager.CreateFailedMessageRetryDocument(batchDocumentId, messageIds[i]);
            }

            await store.AsyncDatabaseCommands.BatchAsync(commands)
            .ConfigureAwait(false);

            await retryDocumentManager.MoveBatchToStaging(batchDocumentId).ConfigureAwait(false);

            log.InfoFormat("Moved Batch '{0}' to Staging", batchDocumentId);
        }
Ejemplo n.º 2
0
        public async Task <string> CreateBatchDocument(string requestId, RetryType retryType, string[] failedMessageRetryIds, string originator, DateTime startTime, DateTime?last = null, string batchName = null, string classifier = null)
        {
            var batchDocumentId = RetryBatch.MakeDocumentId(Guid.NewGuid().ToString());

            using (var session = store.OpenAsyncSession())
            {
                await session.StoreAsync(new RetryBatch
                {
                    Id               = batchDocumentId,
                    Context          = batchName,
                    RequestId        = requestId,
                    RetryType        = retryType,
                    Originator       = originator,
                    Classifier       = classifier,
                    StartTime        = startTime,
                    Last             = last,
                    InitialBatchSize = failedMessageRetryIds.Length,
                    RetrySessionId   = RetrySessionId,
                    FailureRetries   = failedMessageRetryIds,
                    Status           = RetryBatchStatus.MarkingDocuments
                }).ConfigureAwait(false);

                await session.SaveChangesAsync().ConfigureAwait(false);
            }

            return(batchDocumentId);
        }
Ejemplo n.º 3
0
        public void StageRetryByUniqueMessageIds(string requestId, RetryType retryType, string[] messageIds, DateTime startTime, DateTime?last = null, string originator = null, string batchName = null, string classifier = null)
        {
            if (messageIds == null || !messageIds.Any())
            {
                log.DebugFormat("Batch '{0}' contains no messages", batchName);
                return;
            }

            var batchDocumentId = retryDocumentManager.CreateBatchDocument(requestId, retryType, messageIds.Length, originator, startTime, last, batchName, classifier);

            log.InfoFormat("Created Batch '{0}' with {1} messages for '{2}'", batchDocumentId, messageIds.Length, batchName);

            var retryIds = new string[messageIds.Length];
            var commands = new ICommandData[messageIds.Length];

            for (var i = 0; i < messageIds.Length; i++)
            {
                commands[i] = retryDocumentManager.CreateFailedMessageRetryDocument(batchDocumentId, messageIds[i]);
                retryIds[i] = commands[i].Key;
            }

            store.DatabaseCommands.Batch(commands);

            retryDocumentManager.MoveBatchToStaging(batchDocumentId, retryIds);
            log.InfoFormat("Moved Batch '{0}' to Staging", batchDocumentId);
        }
Ejemplo n.º 4
0
        public RetryOperation GetStatusForRetryOperation(string requestId, RetryType retryType)
        {
            RetryOperation summary;

            Operations.TryGetValue(RetryOperation.MakeOperationId(requestId, retryType), out summary);

            return(summary);
        }
Ejemplo n.º 5
0
        public InMemoryRetry GetStatusForRetryOperation(string requestId, RetryType retryType)
        {
            InMemoryRetry summary;

            RetryOperations.TryGetValue(InMemoryRetry.MakeOperationId(requestId, retryType), out summary);

            return(summary);
        }
Ejemplo n.º 6
0
        public bool IsOperationInProgressFor(string requestId, RetryType retryType)
        {
            if (!retryOperations.TryGetValue(InMemoryRetry.MakeOperationId(requestId, retryType), out var summary))
            {
                return(false);
            }

            return(summary.IsInProgress());
        }
Ejemplo n.º 7
0
 public IndexBasedBulkRetryRequest(string requestId, RetryType retryType, string originator, string classifier, DateTime startTime, Expression <Func <TType, bool> > filter)
 {
     RequestId   = requestId;
     RetryType   = retryType;
     Originator  = originator;
     this.filter = filter;
     StartTime   = startTime;
     Classifier  = classifier;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RetryReliability"/> class.
 /// </summary>
 /// <param name="maxRetryCount">The maximum retry count</param>
 /// <param name="retryInterval">The interval in which the retry should happen</param>
 /// <param name="type">The type of the retry</param>
 private RetryReliability(
     int maxRetryCount,
     TimeSpan retryInterval,
     RetryType type) : this()
 {
     MaxRetryCount = maxRetryCount;
     RetryInterval = retryInterval;
     RetryType     = type;
 }
Ejemplo n.º 9
0
        private InMemoryRetry GetOrCreate(RetryType retryType, string requestId)
        {
            if (!retryOperations.TryGetValue(InMemoryRetry.MakeOperationId(requestId, retryType), out var summary))
            {
                summary = new InMemoryRetry(requestId, retryType, domainEvents);
                retryOperations[InMemoryRetry.MakeOperationId(requestId, retryType)] = summary;
            }

            return(summary);
        }
Ejemplo n.º 10
0
        public void StartRetryForIndex <TType, TIndex>(string requestId, RetryType retryType, DateTime startTime, Expression <Func <TType, bool> > filter = null, string originator = null, string classifier = null)
            where TIndex : AbstractIndexCreationTask, new()
            where TType : IHaveStatus
        {
            log.InfoFormat("Enqueuing index based bulk retry '{0}'", originator);

            var request = new IndexBasedBulkRetryRequest <TType, TIndex>(requestId, retryType, originator, classifier, startTime, filter);

            bulkRequests.Enqueue(request);
        }
Ejemplo n.º 11
0
        public async Task PreparedBatch(string requestId, RetryType retryType, int numberOfMessagesPrepared)
        {
            if (requestId == null) //legacy support for batches created before operations were introduced
            {
                return;
            }

            var summary = GetOrCreate(retryType, requestId);

            await summary.PrepareBatch(numberOfMessagesPrepared).ConfigureAwait(false);
        }
Ejemplo n.º 12
0
        public bool IsOperationInProgressFor(string requestId, RetryType retryType)
        {
            RetryOperation summary;

            if (!Operations.TryGetValue(RetryOperation.MakeOperationId(requestId, retryType), out summary))
            {
                return(false);
            }

            return(summary.RetryState != RetryState.Completed && summary.RetryState != RetryState.Waiting);
        }
Ejemplo n.º 13
0
        private RetryOperation GetOrCreate(RetryType retryType, string requestId)
        {
            RetryOperation summary;

            if (!Operations.TryGetValue(RetryOperation.MakeOperationId(requestId, retryType), out summary))
            {
                summary = new RetryOperation(requestId, retryType);
                Operations[RetryOperation.MakeOperationId(requestId, retryType)] = summary;
            }
            return(summary);
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Creates a <see cref="RetryReliability"/> instance referencing a <see cref="InMessage"/>.
 /// </summary>
 /// <param name="refToInMessageId">Reference to the <see cref="InMessage"/> entity</param>
 /// <param name="maxRetryCount">The maximum retry count</param>
 /// <param name="retryInterval">The interval in which the retry should happen</param>
 /// <param name="type">The type of the retry</param>
 /// <returns></returns>
 public static RetryReliability CreateForInMessage(
     long refToInMessageId,
     int maxRetryCount,
     TimeSpan retryInterval,
     RetryType type)
 {
     return(new RetryReliability(maxRetryCount, retryInterval, type)
     {
         RefToInMessageId = refToInMessageId
     });
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Creates a <see cref="RetryReliability"/> instance referencing a <see cref="OutException"/>.
 /// </summary>
 /// <param name="refToOutExceptionId">Reference to the <see cref="OutException"/> entity</param>
 /// <param name="maxRetryCount">The maximum retry count</param>
 /// <param name="retryInterval">The interval in which the retry should happen</param>
 /// <param name="type">The type of the retry</param>
 /// <returns></returns>
 public static RetryReliability CreateForOutException(
     long refToOutExceptionId,
     int maxRetryCount,
     TimeSpan retryInterval,
     RetryType type)
 {
     return(new RetryReliability(maxRetryCount, retryInterval, type)
     {
         RefToOutExceptionId = refToOutExceptionId
     });
 }
Ejemplo n.º 16
0
        public async Task Forwarding(string requestId, RetryType retryType)
        {
            if (requestId == null) //legacy support for batches created before operations were introduced
            {
                return;
            }

            var summary = Get(requestId, retryType);

            await summary.Forwarding().ConfigureAwait(false);
        }
 private void GetDefaultRetrySetting(SettingsManager smng, out RetryType defaultRetryType, out int defaultRetryCount)
 {
     if (!smng.TryGetItem(SettingsConstants.DEFAULT_RETRY_TYPE, out defaultRetryType))
     {
         defaultRetryType = RetryType.None;
     }
     if (!smng.TryGetItem(SettingsConstants.DEFAULT_RETRY_COUNT, out defaultRetryCount))
     {
         defaultRetryCount = 0;
     }
 }
Ejemplo n.º 18
0
        public void Forwarding(string requestId, RetryType retryType)
        {
            if (requestId == null) //legacy support for batches created before operations were introduced
            {
                return;
            }

            var summary = Get(requestId, retryType);

            summary.Forwarding();
        }
Ejemplo n.º 19
0
        public void ForwardedBatch(string requestId, RetryType retryType, int numberOfMessagesForwarded)
        {
            if (requestId == null) //legacy support for batches created before operations were introduced
            {
                return;
            }

            var summary = Get(requestId, retryType);

            summary.BatchForwarded(numberOfMessagesForwarded);
        }
Ejemplo n.º 20
0
        private InMemoryRetry GetOrCreate(RetryType retryType, string requestId)
        {
            InMemoryRetry summary;

            if (!RetryOperations.TryGetValue(InMemoryRetry.MakeOperationId(requestId, retryType), out summary))
            {
                summary = new InMemoryRetry(requestId, retryType);
                RetryOperations[InMemoryRetry.MakeOperationId(requestId, retryType)] = summary;
            }
            return(summary);
        }
Ejemplo n.º 21
0
        public void PreparedBatch(string requestId, RetryType retryType, int numberOfMessagesPrepared)
        {
            if (requestId == null) //legacy support for batches created before operations were introduced
            {
                return;
            }

            var summary = GetOrCreate(retryType, requestId);

            summary.PrepareBatch(numberOfMessagesPrepared);
        }
Ejemplo n.º 22
0
        public void Fail(RetryType retryType, string requestId)
        {
            if (requestId == null) //legacy support for batches created before operations were introduced
            {
                return;
            }

            var summary = GetOrCreate(retryType, requestId);

            summary.Fail();
        }
Ejemplo n.º 23
0
        public void Wait(string requestId, RetryType retryType, DateTime started, string originator = null, string classifier = null, DateTime?last = null)
        {
            if (requestId == null) //legacy support for batches created before operations were introduced
            {
                return;
            }

            var summary = GetOrCreate(retryType, requestId);

            summary.Wait(started, originator, classifier, last);
        }
Ejemplo n.º 24
0
 /// <summary>
 /// Convert an enum of type RetryType to a string.
 /// </summary>
 /// <param name='value'>
 /// The value to convert to a string.
 /// </param>
 /// <returns>
 /// The enum value as a string.
 /// </returns>
 internal static string RetryTypeToString(RetryType value)
 {
     if (value == RetryType.None)
     {
         return("none");
     }
     if (value == RetryType.Fixed)
     {
         return("fixed");
     }
     throw new ArgumentOutOfRangeException("value");
 }
Ejemplo n.º 25
0
        public void PreparedAdoptedBatch(string requestId, RetryType retryType, int numberOfMessagesPrepared, int totalNumberOfMessages, string originator, string classifier, DateTime startTime, DateTime last)
        {
            if (requestId == null) //legacy support for batches created before operations were introduced
            {
                return;
            }

            var summary = GetOrCreate(retryType, requestId);

            summary.Prepare(totalNumberOfMessages);
            summary.PrepareAdoptedBatch(numberOfMessagesPrepared, originator, classifier, startTime, last);
        }
Ejemplo n.º 26
0
        internal static string ToSerializedValue(this RetryType value)
        {
            switch (value)
            {
            case RetryType.None:
                return("None");

            case RetryType.Fixed:
                return("Fixed");
            }
            return(null);
        }
Ejemplo n.º 27
0
 internal RetryOptions(RetryType retryType, ExceptionHandling exceptionHandling, BufferOverflow bufferOverflow,
                       int?bufferSizeBytes = null, int?retryAttempts = null, TimeSpan?retryInterval = null)
 {
     RetryType         = GaxPreconditions.CheckEnumValue(retryType, nameof(retryType));
     ExceptionHandling = GaxPreconditions.CheckEnumValue(exceptionHandling, nameof(exceptionHandling));
     BufferOverflow    = GaxPreconditions.CheckEnumValue(bufferOverflow, nameof(bufferOverflow));
     BufferSizeBytes   = GaxPreconditions.CheckArgumentRange(
         bufferSizeBytes ?? 0, nameof(bufferSizeBytes), 0, int.MaxValue);
     RetryAttempts = GaxPreconditions.CheckArgumentRange(
         retryAttempts ?? 0, nameof(retryAttempts), 0, int.MaxValue);
     RetryInterval = retryInterval ?? TimeSpan.Zero;
     GaxPreconditions.CheckArgument(RetryInterval >= TimeSpan.Zero, nameof(retryInterval),
                                    $"{nameof(retryInterval)} must be greater than 0");
 }
Ejemplo n.º 28
0
        public IVerb WithRetries(RetryType retryType, object retryParameter, int maxRetries, int interval)
        {
            RetryType = retryType;
            RetryParameter = retryParameter;
            MaxRetries = maxRetries;
            Interval = interval;

            for (var i = 0; i < maxRetries; i++)
            {
                httpRequestMessageList.Add(new HttpRequestMessage());
            }

            return this;
        }
Ejemplo n.º 29
0
        public string CreateBatchDocument(string requestId, RetryType retryType, int initialBatchSize, string originator, DateTime startTime, DateTime?last = null, string batchName = null, string classifier = null)
        {
            var batchDocumentId = RetryBatch.MakeDocumentId(Guid.NewGuid().ToString());

            using (var session = store.OpenSession())
            {
                session.Store(new RetryBatch
                {
                    Id               = batchDocumentId,
                    Context          = batchName,
                    RequestId        = requestId,
                    RetryType        = retryType,
                    Originator       = originator,
                    Classifier       = classifier,
                    StartTime        = startTime,
                    Last             = last,
                    InitialBatchSize = initialBatchSize,
                    RetrySessionId   = RetrySessionId,
                    Status           = RetryBatchStatus.MarkingDocuments
                });
                session.SaveChanges();
            }
            return(batchDocumentId);
        }
Ejemplo n.º 30
0
 /// <summary>
 /// Initializes a new instance of the RetryPolicy class with required
 /// arguments.
 /// </summary>
 public RetryPolicy(RetryType retryType)
     : this()
 {
     this.RetryType = retryType;
 }
Ejemplo n.º 31
0
        private static bool IsRetryConditionSatisfied(HttpResponseMessage httpResponseMessage, RetryType retryType, object retryParameter)
        {
            switch (retryType)
            {
                case RetryType.UntilStatusCodeEquals:
                    {
                        if (httpResponseMessage.StatusCode == (HttpStatusCode)retryParameter)
                        {
                            return true;
                        }
                        break;
                    }
                case RetryType.UntilBodyIncludes:
                    {
                        var result = httpResponseMessage.Content.ReadAsStringAsync().Result;
                        var enumerableParameter = retryParameter as IEnumerable<object>;
                        if (enumerableParameter != null)
                        {
                            if (enumerableParameter.All(p => result.Contains(p.ToString())))
                                return true;
                        }
                        else if (result.Contains(retryParameter.ToString()))
                        {
                            return true;
                        }
                        break;
                    }
                case RetryType.UntilBodyDoesNotInclude:
                    {
                        var result = httpResponseMessage.Content.ReadAsStringAsync().Result;
                        var enumerableParameter = retryParameter as IEnumerable<object>;
                        if (enumerableParameter != null)
                        {
                            if (!enumerableParameter.Any(p => result.Contains(p.ToString())))
                                return true;
                        }
                        else if (!result.Contains(retryParameter.ToString()))
                        {
                            return true;
                        }
                        break;
                    }
            }

            return false;
        }
Ejemplo n.º 32
0
 private static InMemoryRetry Get(string requestId, RetryType retryType)
 {
     return(RetryOperations[InMemoryRetry.MakeOperationId(requestId, retryType)]);
 }
Ejemplo n.º 33
0
 private static HistoricRetryOperation GetLatestHistoricOperation(RetryHistory history, string requestId, RetryType retryType)
 {
     return(history.HistoricOperations
            .Where(v => v.RequestId == requestId && v.RetryType == retryType)
            .OrderByDescending(v => v.CompletionTime)
            .FirstOrDefault());
 }