/// <summary> /// Adds a new time consumer element to be monitored /// </summary> /// <param name="consumer">Time consumer instance</param> public void Add(TimeConsumer consumer) { lock (TimeConsumers) { TimeConsumers.Add(consumer); } }
/// <summary> /// Process the TimeConsumer object in TimeConsumers list /// </summary> /// <param name="consumer">The TimeConsumer object to be processed</param> /// <remarks>This method is protected because it's overrode by a test class /// in `IsolatorLimitResultProviderTests.cs`</remarks> protected virtual void ProcessConsumer(TimeConsumer consumer) { if (consumer.NextTimeRequest == null) { // first time, for performance we register this here and not the time consumer consumer.NextTimeRequest = consumer.TimeProvider.GetUtcNow().AddMinutes(1); } else if (consumer.TimeProvider.GetUtcNow() >= consumer.NextTimeRequest) { // each minute request additional time from the isolator consumer.NextTimeRequest = consumer.NextTimeRequest.Value.AddMinutes(1); try { // this will notify the isolator that we've exceed the limits consumer.IsolatorLimitProvider.RequestAdditionalTime(minutes: 1); } catch { // pass } } }