public void Handle(RetryAllInGroup message) { if (Retries == null) { log.Warn($"Attempt to retry a group ({message.GroupId}) when retries are disabled"); return; } if (ArchivingManager.IsArchiveInProgressFor(message.GroupId)) { log.Warn($"Attempt to retry a group ({message.GroupId}) which is currently in the process of being archived"); return; } FailureGroupView group; using (var session = Store.OpenSession()) { group = session.Query <FailureGroupView, FailureGroupsViewIndex>() .FirstOrDefault(x => x.Id == message.GroupId); } string originator = null; if (@group?.Title != null) { originator = group.Title; } var started = message.Started ?? DateTime.UtcNow; RetryingManager.Wait(message.GroupId, RetryType.FailureGroup, started, originator, group?.Type, group?.Last); Retries.StartRetryForIndex <FailureGroupMessageView, FailedMessages_ByGroup>(message.GroupId, RetryType.FailureGroup, started, x => x.FailureGroupId == message.GroupId, originator, group?.Type); }
// Recursive, retry-logic, state-machine function public async Task <Todo> Start() { // let's keep track of our function's status Console.WriteLine(); Console.WriteLine("status: " + Status.ToString()); Console.WriteLine("retries: " + Retries.ToString()); // if Start() is called with the CircuitBreaker status being OPEN if (Status == Status.OPEN) { try { // lets do our initial call return(await Call().ConfigureAwait(false)); } catch (Exception badResponse) { // do something with bad_response... Console.WriteLine(badResponse.Message); // set status to HALFOPEN because our initial request failed Status = Status.HALFOPEN; Retries++; return(await Start().ConfigureAwait(false)); // retry with our Status being HALFOPEN } } // if Start() is called with the CircuitBreaker status being HALFOPEN if (Status == Status.HALFOPEN) { Console.WriteLine("TIMEOUT..."); Thread.Sleep(TimeOut); try { // try a call again return(await Call().ConfigureAwait(false)); } catch { if (Retries < RetryCount) // did we retry too many times already? { Retries++; return(await Start().ConfigureAwait(false)); // Start this function again with the same status HALFOPEN } // looks like we retried too many times, time to set status to CLOSED Status = Status.CLOSED; return(await Start().ConfigureAwait(false)); } } // if Start() is called with the CircuitBreaker status being CLOSED if (Status == Status.CLOSED) { // we throw our final error message throw new Exception($"CircuitBreaker failed for { Url} : { Retries} " + $"times: TimeOut { TimeOut}"); } return(await Start().ConfigureAwait(false)); // this should never be reached, but acts as a safety-net }
public Task Handle(RetryMessagesByQueueAddress message, IMessageHandlerContext context) { var failedQueueAddress = message.QueueAddress; Retries.StartRetryForIndex <FailedMessageViewIndex.SortAndFilterOptions, FailedMessageViewIndex>(failedQueueAddress, RetryType.ByQueueAddress, DateTime.UtcNow, m => m.QueueAddress == failedQueueAddress && m.Status == message.Status, $"all messages for failed queue address '{message.QueueAddress}'"); return(Task.FromResult(0)); }
public override int GetHashCode() { int hash = 1; if (Timestamp != 0L) { hash ^= Timestamp.GetHashCode(); } if (GlobalTxId.Length != 0) { hash ^= GlobalTxId.GetHashCode(); } if (LocalTxId.Length != 0) { hash ^= LocalTxId.GetHashCode(); } if (ParentTxId.Length != 0) { hash ^= ParentTxId.GetHashCode(); } if (Type.Length != 0) { hash ^= Type.GetHashCode(); } if (CompensationMethod.Length != 0) { hash ^= CompensationMethod.GetHashCode(); } if (Payloads.Length != 0) { hash ^= Payloads.GetHashCode(); } if (ServiceName.Length != 0) { hash ^= ServiceName.GetHashCode(); } if (InstanceId.Length != 0) { hash ^= InstanceId.GetHashCode(); } if (Timeout != 0) { hash ^= Timeout.GetHashCode(); } if (Retries != 0) { hash ^= Retries.GetHashCode(); } if (RetryMethod.Length != 0) { hash ^= RetryMethod.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public void SaveEvents(string aggregateId, IEnumerable <IEvent> newEvents, Type aggregateType) { if (GetAggregateEventCount(aggregateId) == 0) { SaveAggregate(aggregateId, aggregateType); } Retries.Retry(() => InternalSaveEvents(aggregateId, newEvents), new TimeSpan(0, 0, 2), 5); }
// service bus best practices for performance: // http://msdn.microsoft.com/en-us/library/windowsazure/hh528527.aspx public void Send(ISendContext context) { _connectionHandler .Use(connection => { // don't have too many outstanding at same time SpinWait.SpinUntil(() => _messagesInFlight < _settings.MaxOutstanding); using (var body = new MemoryStream()) { context.SerializeTo(body); // the envelope is re-usable, so let's capture it in the below closure // as a value var envelope = new MessageEnvelope(body.ToArray()); var sending = Retries.Retry(FaultPolicies.FinalAzurePolicy, new Func <AsyncCallback, object, IAsyncResult>((cb, state) => { return(SendMessage(connection, () => { var brokeredMessage = new BrokeredMessage(envelope); if (!string.IsNullOrWhiteSpace(context.CorrelationId)) { brokeredMessage.CorrelationId = context.CorrelationId; } if (!string.IsNullOrWhiteSpace(context.MessageId)) { brokeredMessage.MessageId = context.MessageId; } return brokeredMessage; }, 1, cb, state)); }), (IAsyncResult ar) => { var state = (StateHolder)ar.AsyncState; Interlocked.Decrement(ref _messagesInFlight); try { state.Sender.EndSend(ar); Address.LogEndSend(state.Message.MessageId); } finally { // always dispose the message; it's only good once state.Message.Dispose(); } }); sending.Wait(); } }); }
private void FetchTiles(Retries retries) { foreach (var info in _missingTiles) { if (_threadCount >= _maxThreads) { break; } FetchTile(info, retries); } }
public void Handle(RequestRetryAll message) { if (!string.IsNullOrWhiteSpace(message.Endpoint)) { Retries.StartRetryForIndex <FailedMessageViewIndex.SortAndFilterOptions, FailedMessageViewIndex>(message.Endpoint, RetryType.AllForEndpoint, DateTime.UtcNow, m => m.ReceivingEndpointName == message.Endpoint, "all messages for endpoint " + message.Endpoint); } else { Retries.StartRetryForIndex <FailedMessage, FailedMessageViewIndex>("All", RetryType.All, DateTime.UtcNow, originator: "all messages"); } }
public void RetryOnException_Okay() { int attempts = 0; bool call() { attempts++; return(true); } Retries.RetryOnException <RetryException, bool>(call, "test call").Should().BeTrue(); attempts.Should().Be(1); }
public void RetryOnException_RepeatedException() { int attempts = 0; bool call() { attempts++; throw new RetryException(); } Action callingRetry = () => Retries.RetryOnException <RetryException, bool>(call, "test call"); callingRetry.Should().Throw <RetryException>(); attempts.Should().Be(3); }
public void RetryOnException_ImmediateAbort() { int attempts = 0; bool call() { attempts++; throw new Exception(); } Action callingRetry = () => Retries.RetryOnException <RetryException, bool>(call, "test call"); callingRetry.Should().Throw <Exception>(); attempts.Should().Be(1); }
protected override void Execute(NativeActivityContext context) { this._context = ContextName.Get(context); string aFolder = ""; if (Retries == null || Retries.Get(context) <= 0) { throw new Exception("Retries cannot be zero or negative."); } if (InputFolder != null) { aFolder = InputFolder.Get(context); } Dictionary <string, string> aArguments = new Dictionary <string, string>(); aArguments["Folder"] = aFolder; aArguments["Retries"] = Retries.Get(context).ToString(); try { aContext = new ContextClient(ContextType, this._context, aArguments, this.Debug); aContext.CreateClient(); if (ContextType == contextType.File && this.ClearContext) { aContext.ClearAll(); } if (Body != null) { //scheduling the execution of the child activities // and passing the value of the delegate argument context.ScheduleAction(Body, aContext, OnCompleted, OnFaulted); } } catch (Exception exception) { if (this.Debug) { Console.WriteLine("[SharedContext Scope] There is an error!!"); Console.WriteLine(exception.Message); } CleanupContext(); throw; } }
public void RetryOnException_OneException() { int attempts = 0; bool call() { if (attempts++ == 0) { throw new RetryException(); } return(true); } Retries.RetryOnException <RetryException, bool>(call, "test call").Should().BeTrue(); attempts.Should().Be(2); }
/// <summary> /// Return the HashCode of this object. /// </summary> /// <returns>The HashCode of this object.</returns> public override Int32 GetHashCode() { unchecked { return(Location.GetHashCode() * 11 ^ RetrieveDate.GetHashCode() * 7 ^ (Retries.HasValue ? Retries.GetHashCode() * 5 : 0) ^ (RetryInterval.HasValue ? RetryInterval.GetHashCode() : 0)); } }
private void TileFetchLoop() { try { var retries = new Retries(_maxAttempts); while (_isThreadRunning) { if (_tileSource.Schema == null) { _waitHandle.Reset(); } _waitHandle.WaitOne(); Busy = true; if (_isViewChanged && (_tileSource.Schema != null)) { var levelId = BruTile.Utilities.GetNearestLevel(_tileSource.Schema.Resolutions, _resolution); _missingTiles = _strategy.GetTilesWanted(_tileSource.Schema, _extent.ToExtent(), levelId); _numberTilesNeeded = _missingTiles.Count; retries.Clear(); _isViewChanged = false; } _missingTiles = GetTilesMissing(_missingTiles, _memoryCache, retries); FetchTiles(retries); if (_missingTiles.Count == 0) { Busy = false; _waitHandle.Reset(); } if (_threadCount >= _maxThreads) { _waitHandle.Reset(); } } } finally { _isThreadRunning = false; } }
private void FetchLoop() { IEnumerable <TileInfo> tilesWanted = null; if (_retries == null) { _retries = new Retries(); } while (!_isAborted) { _waitHandle.WaitOne(); if (_tileSource.Schema == null) { _waitHandle.Reset(); // set in wait mode continue; // and go to begin of loop to wait } if (_isViewChanged || tilesWanted == null) { var levelId = Utilities.GetNearestLevel(_tileSource.Schema.Resolutions, _unitsPerPixel); tilesWanted = _strategy.GetTilesWanted(_tileSource.Schema, _extent, levelId); _retries.Clear(); _isViewChanged = false; } var tilesMissing = GetTilesMissing(tilesWanted, _memoryCache, _retries); FetchTiles(tilesMissing); if (tilesMissing.Count == 0) { _waitHandle.Reset(); } lock (_tilesInProgress) { if (_tilesInProgress.Count >= MaxThreads) { _waitHandle.Reset(); } } } }
private IList <TileInfo> GetTilesMissing(IEnumerable <TileInfo> tileInfos, MemoryCache <Feature> memoryCache, Retries retries) { var result = new List <TileInfo>(); foreach (var info in tileInfos) { if (retries.ReachedMax(info.Index)) { continue; } if (memoryCache.Find(info.Index) == null) { result.Add(info); } } return(result); }
/// <inheritdocs /> public override int GetHashCode() { var hashCode = -1775804580; hashCode = hashCode * -1521134295 + EqualityComparer <NameServer[]> .Default.GetHashCode(_endpoints); hashCode = hashCode * -1521134295 + EnableAuditTrail.GetHashCode(); hashCode = hashCode * -1521134295 + UseCache.GetHashCode(); hashCode = hashCode * -1521134295 + Recursion.GetHashCode(); hashCode = hashCode * -1521134295 + Retries.GetHashCode(); hashCode = hashCode * -1521134295 + ThrowDnsErrors.GetHashCode(); hashCode = hashCode * -1521134295 + UseRandomNameServer.GetHashCode(); hashCode = hashCode * -1521134295 + ContinueOnDnsError.GetHashCode(); hashCode = hashCode * -1521134295 + EqualityComparer <TimeSpan> .Default.GetHashCode(Timeout); hashCode = hashCode * -1521134295 + UseTcpFallback.GetHashCode(); hashCode = hashCode * -1521134295 + UseTcpOnly.GetHashCode(); hashCode = hashCode * -1521134295 + AutoResolvedNameServers.GetHashCode(); return(hashCode); }
private IEnumerable <Task <bool> > Run <TComponentType>( Func <TComponentType, ComponentTree, Task <bool> > execute, string actionName) where TComponentType : IComponent { foreach (var component in _components.OfType <TComponentType>()) { yield return(Retries.RetryOnException( () => execute(component, this), $"{component.Name}.{actionName}")); } foreach (var child in _children) { foreach (var childRun in child.Run(execute, actionName)) { yield return(childRun); } } }
public override int GetHashCode() { int hash = 1; if (Name.Length != 0) { hash ^= Name.GetHashCode(); } if (ContainerImage.Length != 0) { hash ^= ContainerImage.GetHashCode(); } if (Shell.Length != 0) { hash ^= Shell.GetHashCode(); } if (WorkingDirectory.Length != 0) { hash ^= WorkingDirectory.GetHashCode(); } hash ^= commands_.GetHashCode(); if (When.Length != 0) { hash ^= When.GetHashCode(); } hash ^= EnvVars.GetHashCode(); if (AutoInjected != false) { hash ^= AutoInjected.GetHashCode(); } if (Retries != 0L) { hash ^= Retries.GetHashCode(); } hash ^= CustomProperties.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
private void FetchTile(TileInfo info, Retries retries) { if (retries.ReachedMax(info.Index)) { return; } lock (_tilesInProgress) { if (_tilesInProgress.Contains(info.Index)) { return; } _tilesInProgress.Add(info.Index); } retries.PlusOne(info.Index); _threadCount++; StartFetchOnThread(info); }
/// <summary> /// Return the HashCode of this object. /// </summary> /// <returns>The HashCode of this object.</returns> public override Int32 GetHashCode() { unchecked { return(Location.GetHashCode() * 11 ^ (StartTime.HasValue ? StartTime.GetHashCode() * 7 : 0) ^ (StopTime.HasValue ? StopTime.GetHashCode() * 5 : 0) ^ (Retries.HasValue ? Retries.GetHashCode() * 3 : 0) ^ (RetryInterval.HasValue ? RetryInterval.GetHashCode() : 0)); } }
private void FetchTiles(Retries retries) { foreach (var info in _missingTiles) { if (_threadCount >= _maxThreads) break; FetchTile(info, retries); } }
public Task Handle(RetryMessagesById message, IMessageHandlerContext context) { return(Retries.StartRetryForMessageSelection(message.MessageUniqueIds)); }
public Task Handle(RetryMessage message, IMessageHandlerContext context) { return(Retries.StartRetryForSingleMessage(message.FailedMessageId)); }
public RetryPolicy(Retries maxNoOfRetries, Func <int, TimeSpan> sleepDurationProvider) { MaxNoOfRetries = maxNoOfRetries; SleepDurationProvider = sleepDurationProvider; RetryType = RetryType.Provider; }
private static IList <TileInfo> GetTilesMissing(IEnumerable <TileInfo> tilesWanted, ITileCache <Tile <T> > memoryCache, Retries retries) { return(tilesWanted.Where( info => memoryCache.Find(info.Index) == null && !retries.ReachedMax(info.Index)).ToList()); }
private IList<TileInfo> GetTilesMissing(IEnumerable<TileInfo> tileInfos, MemoryCache<Feature> memoryCache, Retries retries) { var result = new List<TileInfo>(); foreach (var info in tileInfos) { if (retries.ReachedMax(info.Index)) continue; if (memoryCache.Find(info.Index) == null) result.Add(info); } return result; }
public void Handle(RetryMessagesByQueueAddress message) { var failedQueueAddress = message.QueueAddress; Retries.StartRetryForIndex <FailedMessageViewIndex.SortAndFilterOptions, FailedMessageViewIndex>(failedQueueAddress, RetryType.ByQueueAddress, DateTime.UtcNow, m => m.QueueAddress == failedQueueAddress && m.Status == message.Status, $"all messages for failed queue address '{message.QueueAddress}'"); }
public void Handle(RetryMessage message) { Retries.StageRetryByUniqueMessageIds(message.FailedMessageId, RetryType.SingleMessage, new[] { message.FailedMessageId }, DateTime.UtcNow); }
public void Handle(RetryMessagesById message) { Retries.StageRetryByUniqueMessageIds(Guid.NewGuid().ToString(), RetryType.MultipleMessages, message.MessageUniqueIds, DateTime.UtcNow); }
private void FetchTile(TileInfo info, Retries retries) { if (retries.ReachedMax(info.Index)) return; lock (_tilesInProgress) { if (_tilesInProgress.Contains(info.Index)) return; _tilesInProgress.Add(info.Index); } retries.PlusOne(info.Index); _threadCount++; StartFetchOnThread(info); }
public new ReadModelSubscription SetRetryPolicy(Retries maxNoOfRetries, Func <int, TimeSpan> provider) => (ReadModelSubscription)base.SetRetryPolicy(maxNoOfRetries, provider);
private void TileFetchLoop(object state) { try { var retries = new Retries(_maxAttempts); while (_isThreadRunning) { if (_tileSource.Schema == null) _waitHandle.Reset(); _waitHandle.WaitOne(); Busy = true; if (_isViewChanged && (_tileSource.Schema != null)) { var levelId = BruTile.Utilities.GetNearestLevel(_tileSource.Schema.Resolutions, _resolution); _missingTiles = _strategy.GetTilesWanted(_tileSource.Schema, _extent.ToExtent(), levelId); _numberTilesNeeded = _missingTiles.Count; retries.Clear(); _isViewChanged = false; } _missingTiles = GetTilesMissing(_missingTiles, _memoryCache, retries); FetchTiles(retries); if (_missingTiles.Count == 0) { Busy = false; _waitHandle.Reset(); } if (_threadCount >= _maxThreads) { _waitHandle.Reset(); } } } finally { _isThreadRunning = false; } }