diff --git a/README.md b/README.md index 7f30dd5..8f6544f 100644 --- a/README.md +++ b/README.md @@ -30,12 +30,12 @@ public class SomeEventHandler : IEventHandler { } - public async Task Handle(SomeEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public async Task Handle(SomeEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { // process the event } - public async Task OnError(Exception exception, SomeEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public async Task OnError(Exception exception, SomeEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { // called on unhandled exeption from Handle // optionally use retryPolicy.RetryAfter(TimeSpan) @@ -166,14 +166,14 @@ Retrying within event hadler can become a bottleneck. Imagine `EventBroker` is r Another option will be to use `IEventBroker.PublishDeferred`. This will eliminate the bottleneck but will itroduce different problems. The same event will be handled again by all handlers, meaning specaial care should be taken to make all handlers idempotent. Any additional information (e.g. number of retries) needs to be known, it should be carried with the event, introducing accidential complexity. -To avoid these problems, both `IEventBroker` `Handle` and `OnError` methods have `RetryPolicy` parameter. +To avoid these problems, both `IEventBroker` `Handle` and `OnError` methods have `IRetryPolicy` parameter. - `RetryPolicy.RetryAfter()` will schedule a retry only for the handler it is called from, without blocking. After the given time interval an instance of the handler will be resolved from the DI container (from a new scope) and executed with the same event instance. + `IRetryPolicy.RetryAfter()` will schedule a retry only for the handler it is called from, without blocking. After the given time interval an instance of the handler will be resolved from the DI container (from a new scope) and executed with the same event instance. -`RetryPolicy.Attempt` is the current retry attempt for a given handler and event. -`RetryPolicy.LastDelay` is the time interval before the retry. +`IRetryPolicy.Attempt` is the current retry attempt for a given handler and event. +`IRetryPolicy.LastDelay` is the time interval before the retry. -`RetryPolicy.RetryRequested` is used to coordinate retry request between `Handle` and `OnError`. `RetryPolicy` is passed to both methods to enable error handling and retry request entirely in `Handle` method. `OnError` can check `RetryPolicy.RetryRequested` to know whether `Hanlde` had called `RetryPolicy.RetryAfter()`. +`IRetryPolicy.RetryRequested` is used to coordinate retry request between `Handle` and `OnError`. `IRetryPolicy` is passed to both methods to enable error handling and retry request entirely in `Handle` method. `OnError` can check `IRetryPolicy.RetryRequested` to know whether `Hanlde` had called `IRetryPolicy.RetryAfter()`. -**Caution:** the retry will not be exactly after the specified time interval in `RetryPolicy.RetryAfter()`. Take into account a tolerance of around 50 milliseconds. Additionally, retry executions respect maximum concurrent handlers setting, meaning a high load can cause additional delay. +**Caution:** the retry will not be exactly after the specified time interval in `IRetryPolicy.RetryAfter()`. Take into account a tolerance of around 50 milliseconds. Additionally, retry executions respect maximum concurrent handlers setting, meaning a high load can cause additional delay. diff --git a/package-readme.md b/package-readme.md index 02a75dd..6568959 100644 --- a/package-readme.md +++ b/package-readme.md @@ -26,12 +26,12 @@ public class SomeEventHandler : IEventHandler { } - public async Task Handle(SomeEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public async Task Handle(SomeEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { // process the event } - public async Task OnError(Exception exception, SomeEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public async Task OnError(Exception exception, SomeEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { // called on unhandled exeption from Handle // optionally use retryPolicy.RetryAfter(TimeSpan) diff --git a/src/M.EventBrokerSlim/IEventHandler.cs b/src/M.EventBrokerSlim/IEventHandler.cs index 083e708..76c48f9 100644 --- a/src/M.EventBrokerSlim/IEventHandler.cs +++ b/src/M.EventBrokerSlim/IEventHandler.cs @@ -1,6 +1,7 @@ using System; using System.Threading; using System.Threading.Tasks; +using M.EventBrokerSlim.Internal; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -18,7 +19,7 @@ public interface IEventHandler /// An instance of representing the event. /// Provides ability to request a retry for the same event by the handler. Do not keep a reference to this instance, it may be pooled and reused. /// A cancellation token that should be used to cancel the work - Task Handle(TEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken); + Task Handle(TEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken); /// /// Called when an unhadled exception is caught during execution. @@ -29,5 +30,5 @@ public interface IEventHandler /// The event instance which handling caused the exception. /// Provides ability to request a retry for the same event by the handler. Do not keep a reference to this instance, it may be pooled and reused. /// A cancellation token that should be used to cancel the work - Task OnError(Exception exception, TEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken); + Task OnError(Exception exception, TEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken); } diff --git a/src/M.EventBrokerSlim/RetryPolicy.cs b/src/M.EventBrokerSlim/IRetryPolicy.cs similarity index 54% rename from src/M.EventBrokerSlim/RetryPolicy.cs rename to src/M.EventBrokerSlim/IRetryPolicy.cs index 3ba99f5..9819f49 100644 --- a/src/M.EventBrokerSlim/RetryPolicy.cs +++ b/src/M.EventBrokerSlim/IRetryPolicy.cs @@ -3,61 +3,34 @@ namespace M.EventBrokerSlim; /// -/// Describes a retry request for re-processing an event. +/// Represents a retry request for re-processing an event. /// -public class RetryPolicy +public interface IRetryPolicy { - private TimeSpan _delay; - - internal RetryPolicy() - { - } - /// - /// Requests invoking of the same handler with the same event after given time interval. + /// Current attempt for the same handler and event. /// - /// The time interval to wait before re-processing. - public void RetryAfter(TimeSpan delay) - { - _delay = delay; - RetryRequested = true; - } + uint Attempt { get; } /// - /// Requests invoking of the same handler with the same event after given time interval. + /// The time interval delay used for the last re-processing. /// - /// A func taking the attempt number for the same handler and event and the last retry interval and returning the new wait interval before re-processing. - public void RetryAfter(Func delay) - { - _delay = delay(Attempt, _delay); - RetryRequested = true; - } + TimeSpan LastDelay { get; } /// - /// Current attempt for the same handler and event. + /// Indicates whether a re-processing has been requested for the handler and event. /// - public uint Attempt { get; private set; } + bool RetryRequested { get; } /// - /// The time interval delay used for the last re-processing. + /// Requests invoking of the same handler with the same event after given time interval. /// - public TimeSpan LastDelay => _delay; + /// A func taking the attempt number for the same handler and event and the last retry interval and returning the new wait interval before re-processing. + void RetryAfter(Func delay); /// - /// Indicates whether a re-processing has been requested for the handler and event. + /// Requests invoking of the same handler with the same event after given time interval. /// - public bool RetryRequested { get; private set; } - - internal void NextAttempt() - { - Attempt++; - RetryRequested = false; - } - - internal void Clear() - { - Attempt = 0; - _delay = TimeSpan.Zero; - RetryRequested = false; - } + /// The time interval to wait before re-processing. + void RetryAfter(TimeSpan delay); } diff --git a/src/M.EventBrokerSlim/Internal/RetryPolicy.cs b/src/M.EventBrokerSlim/Internal/RetryPolicy.cs new file mode 100644 index 0000000..50803a3 --- /dev/null +++ b/src/M.EventBrokerSlim/Internal/RetryPolicy.cs @@ -0,0 +1,43 @@ +using System; + +namespace M.EventBrokerSlim.Internal; + +internal class RetryPolicy : IRetryPolicy +{ + private TimeSpan _delay; + + internal RetryPolicy() + { + } + + public void RetryAfter(TimeSpan delay) + { + _delay = delay; + RetryRequested = true; + } + + public void RetryAfter(Func delay) + { + _delay = delay(Attempt, _delay); + RetryRequested = true; + } + + public uint Attempt { get; private set; } + + public TimeSpan LastDelay => _delay; + + public bool RetryRequested { get; private set; } + + internal void NextAttempt() + { + Attempt++; + RetryRequested = false; + } + + internal void Clear() + { + Attempt = 0; + _delay = TimeSpan.Zero; + RetryRequested = false; + } +} diff --git a/test/M.EventBrokerSlim.Tests/EventBrokerTests.cs b/test/M.EventBrokerSlim.Tests/EventBrokerTests.cs index 0fbbfda..793505f 100644 --- a/test/M.EventBrokerSlim.Tests/EventBrokerTests.cs +++ b/test/M.EventBrokerSlim.Tests/EventBrokerTests.cs @@ -392,7 +392,7 @@ public TestEventHandler(EventsRecorder eventsRecorder, Timestamp? timestamp _timestamp = timestamp; } - public async Task Handle(TestEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public async Task Handle(TestEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { _eventsRecoder.Notify(@event); @@ -412,7 +412,7 @@ public async Task Handle(TestEvent @event, RetryPolicy retryPolicy, Cancellation } } - public async Task OnError(Exception exception, TestEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public async Task OnError(Exception exception, TestEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { _eventsRecoder.Notify(exception, @event); diff --git a/test/M.EventBrokerSlim.Tests/ExceptionHandlingTests.cs b/test/M.EventBrokerSlim.Tests/ExceptionHandlingTests.cs index 5fc921b..3b6ba15 100644 --- a/test/M.EventBrokerSlim.Tests/ExceptionHandlingTests.cs +++ b/test/M.EventBrokerSlim.Tests/ExceptionHandlingTests.cs @@ -148,7 +148,7 @@ public TestEventHandler(EventsRecorder eventBroker) _eventsRecorder = eventBroker; } - public Task Handle(TestEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public Task Handle(TestEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { _eventsRecorder.Notify(@event); if(@event.ThrowFromHandle) @@ -159,7 +159,7 @@ public Task Handle(TestEvent @event, RetryPolicy retryPolicy, CancellationToken return Task.CompletedTask; } - public Task OnError(Exception exception, TestEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public Task OnError(Exception exception, TestEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { _eventsRecorder.Notify(exception, @event); if(@event.ThrowFromOnError) @@ -179,8 +179,8 @@ public TestEventHandler1(string input) _input = input; } - public Task Handle(TestEvent @even, RetryPolicy retryPolicyt, CancellationToken cancellationToken) => throw new NotImplementedException(); + public Task Handle(TestEvent @even, IRetryPolicy retryPolicyt, CancellationToken cancellationToken) => throw new NotImplementedException(); - public Task OnError(Exception exception, TestEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) => throw new NotImplementedException(); + public Task OnError(Exception exception, TestEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) => throw new NotImplementedException(); } } diff --git a/test/M.EventBrokerSlim.Tests/HandlerExecutionTests.cs b/test/M.EventBrokerSlim.Tests/HandlerExecutionTests.cs index 2277120..91aad22 100644 --- a/test/M.EventBrokerSlim.Tests/HandlerExecutionTests.cs +++ b/test/M.EventBrokerSlim.Tests/HandlerExecutionTests.cs @@ -156,7 +156,7 @@ public TestEventHandler(EventsRecorder eventsRecorder) _eventsRecoder = eventsRecorder; } - public async Task Handle(TestEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public async Task Handle(TestEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { if(@event.TimeToRun != default) { @@ -166,7 +166,7 @@ public async Task Handle(TestEvent @event, RetryPolicy retryPolicy, Cancellation _eventsRecoder.Notify(@event); } - public Task OnError(Exception exception, TestEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public Task OnError(Exception exception, TestEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { _eventsRecoder.Notify(exception, @event); return Task.CompletedTask; diff --git a/test/M.EventBrokerSlim.Tests/HandlerRegistrationTests.cs b/test/M.EventBrokerSlim.Tests/HandlerRegistrationTests.cs index 1294d95..5f597ab 100644 --- a/test/M.EventBrokerSlim.Tests/HandlerRegistrationTests.cs +++ b/test/M.EventBrokerSlim.Tests/HandlerRegistrationTests.cs @@ -198,13 +198,13 @@ public TestEventHandler(EventsRecorder eventsRecorder) _eventsRecorder = eventsRecorder; } - public Task Handle(TestEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public Task Handle(TestEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { _eventsRecorder.Notify($"{@event.CorrelationId}_{GetType().Name}"); return Task.CompletedTask; } - public Task OnError(Exception exception, TestEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public Task OnError(Exception exception, TestEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { _eventsRecorder.Notify(exception, @event); return Task.CompletedTask; diff --git a/test/M.EventBrokerSlim.Tests/HandlerScopeAndInstanceTests.cs b/test/M.EventBrokerSlim.Tests/HandlerScopeAndInstanceTests.cs index 6c8d66c..e0ec1e2 100644 --- a/test/M.EventBrokerSlim.Tests/HandlerScopeAndInstanceTests.cs +++ b/test/M.EventBrokerSlim.Tests/HandlerScopeAndInstanceTests.cs @@ -117,14 +117,14 @@ public TestEventHandler(EventsRecorder eventsRecorder, IServiceProvider sco _scope = scope; } - public Task Handle(TestEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public Task Handle(TestEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { _eventsRecorder.Notify(@event); _eventsRecorder.Notify(@event, handlerInstance: GetHashCode(), scopeInstance: _scope.GetHashCode()); return Task.CompletedTask; } - public Task OnError(Exception exception, TestEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public Task OnError(Exception exception, TestEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { _eventsRecorder.Notify(exception, @event); return Task.CompletedTask; diff --git a/test/M.EventBrokerSlim.Tests/LoadTests.cs b/test/M.EventBrokerSlim.Tests/LoadTests.cs index 374ef03..e6bdfa3 100644 --- a/test/M.EventBrokerSlim.Tests/LoadTests.cs +++ b/test/M.EventBrokerSlim.Tests/LoadTests.cs @@ -81,7 +81,7 @@ public TestEventHandler1(HandlerSettings settings, EventsTracker tracker) _tracker = tracker; } - public Task Handle(T @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public Task Handle(T @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { _tracker.Track(@event); if(@event.Number % 250 == 0) @@ -91,7 +91,7 @@ public Task Handle(T @event, RetryPolicy retryPolicy, CancellationToken cancella return Task.CompletedTask; } - public Task OnError(Exception exception, T @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public Task OnError(Exception exception, T @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { if(@event.Number % 250 == 0 && retryPolicy.Attempt < _settings.RetryAttempts) { @@ -112,7 +112,7 @@ public TestEventHandler2(HandlerSettings settings, EventsTracker tracker) _tracker = tracker; } - public Task Handle(T @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public Task Handle(T @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { _tracker.Track(@event); if(@event.Number % 500 == 0 && retryPolicy.Attempt < _settings.RetryAttempts) @@ -122,7 +122,7 @@ public Task Handle(T @event, RetryPolicy retryPolicy, CancellationToken cancella return Task.CompletedTask; } - public Task OnError(Exception exception, T @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public Task OnError(Exception exception, T @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { return Task.CompletedTask; } @@ -137,13 +137,13 @@ public TestEventHandler3(EventsTracker tracker) _tracker = tracker; } - public Task Handle(T @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public Task Handle(T @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { _tracker.Track(@event!); return Task.CompletedTask; } - public Task OnError(Exception exception, T @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public Task OnError(Exception exception, T @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { return Task.CompletedTask; } diff --git a/test/M.EventBrokerSlim.Tests/MultipleHandlersTests.cs b/test/M.EventBrokerSlim.Tests/MultipleHandlersTests.cs index e0374ce..f7e597a 100644 --- a/test/M.EventBrokerSlim.Tests/MultipleHandlersTests.cs +++ b/test/M.EventBrokerSlim.Tests/MultipleHandlersTests.cs @@ -48,13 +48,13 @@ public TestEventHandler(EventsRecorder eventsRecorder) _eventsRecorder = eventsRecorder; } - public Task Handle(TestEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public Task Handle(TestEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { _eventsRecorder.Notify($"{@event.CorrelationId}_{GetType().Name}"); return Task.CompletedTask; } - public Task OnError(Exception exception, TestEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public Task OnError(Exception exception, TestEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { _eventsRecorder.Notify(exception, @event); return Task.CompletedTask; diff --git a/test/M.EventBrokerSlim.Tests/OrderOfRetriesTests.cs b/test/M.EventBrokerSlim.Tests/OrderOfRetriesTests.cs index e9e3d02..8cd59a9 100644 --- a/test/M.EventBrokerSlim.Tests/OrderOfRetriesTests.cs +++ b/test/M.EventBrokerSlim.Tests/OrderOfRetriesTests.cs @@ -61,7 +61,7 @@ public TestEventHandler1(EventsTracker tracker) _tracker = tracker; } - public Task Handle(TestEvent1 @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public Task Handle(TestEvent1 @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { _tracker.Track(@event); if(retryPolicy.Attempt < 1) @@ -71,7 +71,7 @@ public Task Handle(TestEvent1 @event, RetryPolicy retryPolicy, CancellationToken throw new NotImplementedException(); } - public Task OnError(Exception exception, TestEvent1 @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public Task OnError(Exception exception, TestEvent1 @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { return Task.CompletedTask; } @@ -86,7 +86,7 @@ public TestEventHandler2(EventsTracker tracker) _tracker = tracker; } - public Task Handle(TestEvent2 @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public Task Handle(TestEvent2 @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { _tracker.Track(@event); if(retryPolicy.Attempt < 2) @@ -96,7 +96,7 @@ public Task Handle(TestEvent2 @event, RetryPolicy retryPolicy, CancellationToken throw new NotImplementedException(); } - public Task OnError(Exception exception, TestEvent2 @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public Task OnError(Exception exception, TestEvent2 @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { return Task.CompletedTask; } diff --git a/test/M.EventBrokerSlim.Tests/RetryFromHandleTests.cs b/test/M.EventBrokerSlim.Tests/RetryFromHandleTests.cs index 80da7be..95421f3 100644 --- a/test/M.EventBrokerSlim.Tests/RetryFromHandleTests.cs +++ b/test/M.EventBrokerSlim.Tests/RetryFromHandleTests.cs @@ -142,7 +142,7 @@ public TestEventHandler(HandlerSettings settings, EventsTracker tracker) _tracker = tracker; } - public async Task Handle(TestEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public async Task Handle(TestEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { _tracker.Track(@event); await Task.Delay(_random.Next(1, 10)); @@ -152,7 +152,7 @@ public async Task Handle(TestEvent @event, RetryPolicy retryPolicy, Cancellation } } - public Task OnError(Exception exception, TestEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public Task OnError(Exception exception, TestEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { return Task.CompletedTask; } diff --git a/test/M.EventBrokerSlim.Tests/RetryFromHandleUsingDelayDelegateTests.cs b/test/M.EventBrokerSlim.Tests/RetryFromHandleUsingDelayDelegateTests.cs index 717e795..7cd70cd 100644 --- a/test/M.EventBrokerSlim.Tests/RetryFromHandleUsingDelayDelegateTests.cs +++ b/test/M.EventBrokerSlim.Tests/RetryFromHandleUsingDelayDelegateTests.cs @@ -112,7 +112,7 @@ public TestEventHandler(HandlerSettings settings, EventsTracker tracker) _tracker = tracker; } - public async Task Handle(TestEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public async Task Handle(TestEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { _tracker.Track(@event); await Task.Delay(_random.Next(1, 10)); @@ -122,7 +122,7 @@ public async Task Handle(TestEvent @event, RetryPolicy retryPolicy, Cancellation } } - public Task OnError(Exception exception, TestEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public Task OnError(Exception exception, TestEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { return Task.CompletedTask; } diff --git a/test/M.EventBrokerSlim.Tests/RetryFromOnErrorTests.cs b/test/M.EventBrokerSlim.Tests/RetryFromOnErrorTests.cs index 852b330..d3b15f7 100644 --- a/test/M.EventBrokerSlim.Tests/RetryFromOnErrorTests.cs +++ b/test/M.EventBrokerSlim.Tests/RetryFromOnErrorTests.cs @@ -144,13 +144,13 @@ public TestEventHandler(HandlerSettings settings, EventsTracker tracker) _tracker = tracker; } - public async Task Handle(TestEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public async Task Handle(TestEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { await Task.Delay(_random.Next(1, 10)); throw new NotImplementedException(); } - public Task OnError(Exception exception, TestEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public Task OnError(Exception exception, TestEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { _tracker.Track(@event); if(retryPolicy.Attempt < _settings.RetryAttempts) diff --git a/test/M.EventBrokerSlim.Tests/RetryFromOnErrorUsingDelayDelegateTests.cs b/test/M.EventBrokerSlim.Tests/RetryFromOnErrorUsingDelayDelegateTests.cs index 72d53bd..efd7351 100644 --- a/test/M.EventBrokerSlim.Tests/RetryFromOnErrorUsingDelayDelegateTests.cs +++ b/test/M.EventBrokerSlim.Tests/RetryFromOnErrorUsingDelayDelegateTests.cs @@ -112,13 +112,13 @@ public TestEventHandler(HandlerSettings settings, EventsTracker tracker) _tracker = tracker; } - public async Task Handle(TestEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public async Task Handle(TestEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { await Task.Delay(_random.Next(1, 10)); throw new NotImplementedException(); } - public Task OnError(Exception exception, TestEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public Task OnError(Exception exception, TestEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { _tracker.Track(@event); diff --git a/test/M.EventBrokerSlim.Tests/RetryOverrideFromOnErrorTests.cs b/test/M.EventBrokerSlim.Tests/RetryOverrideFromOnErrorTests.cs index 8895818..8c2ec37 100644 --- a/test/M.EventBrokerSlim.Tests/RetryOverrideFromOnErrorTests.cs +++ b/test/M.EventBrokerSlim.Tests/RetryOverrideFromOnErrorTests.cs @@ -51,7 +51,7 @@ public TestEventHandler(HandlerSettings settings, EventsTracker tracker) _tracker = tracker; } - public async Task Handle(TestEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public async Task Handle(TestEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { await Task.Delay(_random.Next(1, 10)); if(retryPolicy.Attempt < _settings.RetryAttempts) @@ -62,7 +62,7 @@ public async Task Handle(TestEvent @event, RetryPolicy retryPolicy, Cancellation throw new NotImplementedException(); } - public Task OnError(Exception exception, TestEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public Task OnError(Exception exception, TestEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { _tracker.Track(@event); if(retryPolicy.Attempt < _settings.RetryAttempts) diff --git a/test/M.EventBrokerSlim.Tests/RetryPolicyTests.cs b/test/M.EventBrokerSlim.Tests/RetryPolicyTests.cs index 0cdce05..f9c4ab4 100644 --- a/test/M.EventBrokerSlim.Tests/RetryPolicyTests.cs +++ b/test/M.EventBrokerSlim.Tests/RetryPolicyTests.cs @@ -50,7 +50,7 @@ public TestEventHandler(HandlerSettings settings, EventsTracker tracker) _tracker = tracker; } - public Task Handle(TestEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public Task Handle(TestEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { _tracker.Track(retryPolicy); if(retryPolicy.Attempt < _settings.RetryAttempts) @@ -60,7 +60,7 @@ public Task Handle(TestEvent @event, RetryPolicy retryPolicy, CancellationToken throw new NotImplementedException(); } - public Task OnError(Exception exception, TestEvent @event, RetryPolicy retryPolicy, CancellationToken cancellationToken) + public Task OnError(Exception exception, TestEvent @event, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { _tracker.Track(retryPolicy); if(retryPolicy.Attempt < _settings.RetryAttempts)