protected virtual Task <bool> ShouldHandleAsync(EventExecutionErrorContext context) { if (!Options.EnabledErrorHandle) { return(Task.FromResult(false)); } return(Task.FromResult(Options.ErrorHandleSelector == null || Options.ErrorHandleSelector.Invoke(context.EventType))); }
protected virtual void ThrowOriginalExceptions(EventExecutionErrorContext context) { if (context.Exceptions.Count == 1) { context.Exceptions[0].ReThrow(); } throw new AggregateException( "More than one error has occurred while triggering the event: " + context.EventType, context.Exceptions); }
public virtual async Task TriggerHandlersAsync(Type eventType, object eventData, Action <EventExecutionErrorContext> onErrorAction = null) { var exceptions = new List <Exception>(); await TriggerHandlersAsync(eventType, eventData, exceptions); if (exceptions.Any()) { var context = new EventExecutionErrorContext(exceptions, eventType, this); onErrorAction?.Invoke(context); await ErrorHandler.HandleAsync(context); } }
protected virtual Task <bool> ShouldRetryAsync(EventExecutionErrorContext context) { if (Options.RetryStrategyOptions == null) { return(Task.FromResult(false)); } if (!context.TryGetRetryAttempt(out var retryAttempt)) { return(Task.FromResult(false)); } return(Task.FromResult(Options.RetryStrategyOptions.MaxRetryAttempts > retryAttempt)); }
public virtual async Task HandleAsync(EventExecutionErrorContext context) { if (!await ShouldHandleAsync(context)) { ThrowOriginalExceptions(context); } if (await ShouldRetryAsync(context)) { await RetryAsync(context); return; } await MoveToDeadLetterAsync(context); }
protected abstract Task MoveToDeadLetterAsync(EventExecutionErrorContext context);
protected abstract Task RetryAsync(EventExecutionErrorContext context);