예제 #1
0
        public void ReportErrorForScope(SequencedEvent @event, Action scope, Action<Guid?> aggregateId)
        {
            try
            {
                scope();
            }
            catch (EndOfEventStreamException)
            {
                Thread.Sleep(200);
                Logger.Info("End of stream....");
            }
            catch (TargetInvocationException e)
            {
                var unrolledException = e.UnrollDynamicallyInvokedException();

                try
                {
                    if (SqlTransientExceptionDetector.IsTransient(unrolledException.SourceException))
                    {
                        AwaitInfrastructure();
                        return;
                    }
                    _transactor.ApplyTransactionForLambda(() => HandleError(@event, unrolledException.SourceException, aggregateId));
                }
                catch
                {
                    Logger.Error("Unable to write exception to Database");
                }
            }
            catch (Exception e)
            {
                try
                {
                    if (SqlTransientExceptionDetector.IsTransient(e))
                    {
                        AwaitInfrastructure();
                        return;
                    }
                    _transactor.ApplyTransactionForLambda(() => HandleError(@event, e, aggregateId));
                }
                catch
                {
                    Logger.Error("Unable to write exception to Database");
                }
            }
        }
예제 #2
0
        private bool IsBadSequencedEvent(SequencedEvent sequencedEvent)
        {
            if (!LastBadAggregateId.HasValue) return false;
            if (sequencedEvent == null) return false;

            return LastBadAggregateId.Value == sequencedEvent.AggregateId;
        }
예제 #3
0
 private static bool FinishedReplayingEvents(bool exitAtEndOfStream, SequencedEvent sequencedEvent)
 {
     return exitAtEndOfStream && sequencedEvent != null && !sequencedEvent.HasEvent();
 }
예제 #4
0
 private void PushEventImmediatelyToErrorQueue(SequencedEvent sequencedEvent)
 {
     _errorQueueLoader.PushBack(sequencedEvent.Sequence);
 }
예제 #5
0
        private void ProcessEvent(bool exitAtEndOfStream, SequencedEvent sequencedEvent, bool includeImmediate)
        {
            if (FinishedReplayingEvents(exitAtEndOfStream, sequencedEvent))
                Terminate();

            Process(sequencedEvent, includeImmediate);
        }
예제 #6
0
 private void Process(SequencedEvent sequencedEvent, bool includeImmediate)
 {
     if (sequencedEvent.AggregateId != LastBadAggregateId)
         _errorReporter.ReportErrorForScope(sequencedEvent, () => _handlerExecutor.HandleSequencedEvent(sequencedEvent, includeImmediate? (bool?)null: false), UpdateLastFailedAggregateId);
     else
         _errorReporter.ReportErrorForScope(() => _errorQueueLoader.PushBack(sequencedEvent.Sequence));
 }
예제 #7
0
 private void TransferOthersInSequence(SequencedEvent @event)
 {
     _errorQueueLoader.SeedFromIncluding(@event.Sequence, @event.AggregateId);
 }
예제 #8
0
 private void RecordException(SequencedEvent @event, Exception e)
 {
     var error = new EventHandlerError(@event.EventType, @event.Sequence, e);
     if (LastError != null && LastError == error)
     {
         LastError.Increment();
         _errorRepository.UpdateError(LastError);
         Logger.Error(String.Format("Error on event {0} {1} (count : {2})", @event.EventType, @event.Sequence, LastError.Count));
     }
     else
     {
         _errorRepository.AddError(error);
         LastError = error;
         Logger.Error(String.Format("Error on event {0} {1} {2}", @event.EventType, @event.Sequence, e));
     }
 }
예제 #9
0
        private void HandleError(SequencedEvent @event, Exception e, Action<Guid?> aggregateId)
        {
            AddAuditRecord(@event, e);
            RecordException(@event, e);
            TransferOthersInSequence(@event);

            Logger.Error(String.Format("Error on event {0} {1} {2}", @event.EventType, @event.Sequence, e));

            CallbackDispatcherOnAggregateIdFailure(@event, aggregateId);
        }
예제 #10
0
 private void AddAuditRecord(SequencedEvent @event, Exception e)
 {
     _auditRepository.Add(new EventHandlerAudit(@event.Event, DateTime.UtcNow, EventHandlerAuditResult.Failed, e.Message));
 }
예제 #11
0
 private static void CallbackDispatcherOnAggregateIdFailure(SequencedEvent @event, Action<Guid?> aggregateId)
 {
     aggregateId(@event.AggregateId);
 }