async Task BeginProcessing(CancellationToken cancellationToken) { try { await foreach (var batch in _eventLogStream.ReadAllAsync(cancellationToken)) { if (batch.MatchedEvents.Any()) { var eventsAndPartitions = ConvertToEventsAndPartitions(batch.MatchedEvents); await _eventsWriter.Write(eventsAndPartitions, Identifier.ScopeId, _streamId, cancellationToken).ConfigureAwait(false); } var newState = new StreamProcessorState(batch.To + 1, DateTimeOffset.UtcNow); await _stateProcessorStates.Persist(Identifier, newState, CancellationToken.None).ConfigureAwait(false); _currentState = newState; } } catch (Exception ex) { if (!cancellationToken.IsCancellationRequested) { _logger.FilterStreamProcessingForTenantFailed(ex, Identifier, _tenantId); } } }
async Task <IProcessingResult> HandleResult(IFilterResult result, CommittedEvent @event, PartitionId partitionId, CancellationToken cancellationToken) { _logger.HandleFilterResult(Identifier, Scope, @event.Type.Id, partitionId); if (!result.Succeeded) { _logger.FailedToFilterEvent(Identifier, Scope, @event.Type.Id); return(result); } if (!result.IsIncluded) { return(result); } _logger.FilteredEventIsIncluded(Identifier, Scope, @event.Type.Id, partitionId, Definition.TargetStream); try { await _eventsToStreamsWriter.Write(@event, Scope, Definition.TargetStream, result.Partition, cancellationToken).ConfigureAwait(false); return(result); } catch (Exception ex) { return(new FailedFiltering($"Failed to write filtered event to stream {ex}", true, TimeSpan.FromSeconds(10))); } }
Task HandleResult(IFilterResult result, CommittedEvent @event, PartitionId partitionId, CancellationToken cancellationToken) { _logger.Debug( "{LogMessagePrefix} filtered event '{EventTypeId}' for partition '{PartitionId}' with result 'Succeeded' = {result.Succeeded}", _logMessagePrefix, @event.Type.Id.Value, result.Succeeded); if (result.Succeeded && result.IsIncluded) { _logger.Debug( "{LogMessagePrefix} writing event '{EventTypeId}' to stream '{TargetStream}' in partition '{PartitionId}'", _logMessagePrefix, @event.Type.Id.Value, Definition.TargetStream, partitionId); return(_eventsToStreamsWriter.Write(@event, Scope, Definition.TargetStream, result.Partition, cancellationToken)); } return(Task.CompletedTask); }