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); }
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); }
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); }
public RetryOperation GetStatusForRetryOperation(string requestId, RetryType retryType) { RetryOperation summary; Operations.TryGetValue(RetryOperation.MakeOperationId(requestId, retryType), out summary); return(summary); }
public InMemoryRetry GetStatusForRetryOperation(string requestId, RetryType retryType) { InMemoryRetry summary; RetryOperations.TryGetValue(InMemoryRetry.MakeOperationId(requestId, retryType), out summary); return(summary); }
public bool IsOperationInProgressFor(string requestId, RetryType retryType) { if (!retryOperations.TryGetValue(InMemoryRetry.MakeOperationId(requestId, retryType), out var summary)) { return(false); } return(summary.IsInProgress()); }
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; }
/// <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; }
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); }
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); }
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); }
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); }
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); }
/// <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 }); }
/// <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 }); }
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; } }
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(); }
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); }
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); }
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); }
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(); }
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); }
/// <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"); }
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); }
internal static string ToSerializedValue(this RetryType value) { switch (value) { case RetryType.None: return("None"); case RetryType.Fixed: return("Fixed"); } return(null); }
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"); }
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; }
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); }
/// <summary> /// Initializes a new instance of the RetryPolicy class with required /// arguments. /// </summary> public RetryPolicy(RetryType retryType) : this() { this.RetryType = retryType; }
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; }
private static InMemoryRetry Get(string requestId, RetryType retryType) { return(RetryOperations[InMemoryRetry.MakeOperationId(requestId, retryType)]); }
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()); }