internal void Start(IShardAgent shardAgent, ActionBlock <IStorageOperation> queue, AggregationRuntime <TDoc, TId> runtime, IDocumentStore store, EventRangeGroup parent) { _builder = new TransformBlock <EventSlice <TDoc, TId>, IStorageOperation>(async slice => { if (parent.Cancellation.IsCancellationRequested) { return(null); } IStorageOperation operation = null; await shardAgent.TryAction(async() => { using var session = (DocumentSessionBase)store.LightweightSession(slice.Tenant.TenantId); operation = await runtime.DetermineOperation(session, slice, parent.Cancellation, ProjectionLifecycle.Async); }, parent.Cancellation, group: parent, logException: (l, e) => { l.LogError(e, "Failure trying to build a storage operation to update {DocumentType} with {Id}", typeof(TDoc).FullNameInCode(), slice.Id); }, actionMode: GroupActionMode.Child); return(operation); }, new ExecutionDataflowBlockOptions { CancellationToken = parent.Cancellation, }); _builder.LinkTo(queue, x => x != null); _application = Task.Factory.StartNew(() => processEventSlices(shardAgent, runtime, store, parent.Cancellation) , parent.Cancellation); }
public override async Task ConfigureUpdateBatch(IShardAgent shardAgent, ProjectionUpdateBatch batch, EventRangeGroup eventRangeGroup) { var eventGroupTasks = Groups .Select(x => x.Start(shardAgent, batch.Queue, _runtime, _store, this)) .ToArray(); await Task.WhenAll(eventGroupTasks).ConfigureAwait(false); if (Exception != null) { ExceptionDispatchInfo.Capture(Exception).Throw(); } }
public override async Task ConfigureUpdateBatch(IShardAgent shardAgent, ProjectionUpdateBatch batch, EventRangeGroup eventRangeGroup) { foreach (var @group in Groups) { @group.Start(shardAgent, batch.Queue, _runtime, _store, this); } await Task.WhenAll(Groups.Select(x => x.Complete()).ToArray()); if (Exception != null) { ExceptionDispatchInfo.Capture(Exception).Throw(); } }
public override async Task ConfigureUpdateBatch(IShardAgent shardAgent, ProjectionUpdateBatch batch, EventRangeGroup eventRangeGroup) { #if NET6_0_OR_GREATER await Parallel.ForEachAsync(Groups, CancellationToken.None, async (group, _) => await group.Start(shardAgent, batch.Queue, _runtime, _store, this).ConfigureAwait(false)) .ConfigureAwait(false); #else var eventGroupTasks = Groups .Select(x => x.Start(shardAgent, batch.Queue, _runtime, _store, this)) .ToArray(); await Task.WhenAll(eventGroupTasks).ConfigureAwait(false); #endif if (Exception != null) { ExceptionDispatchInfo.Capture(Exception).Throw(); } }
internal async Task Start(IShardAgent shardAgent, ProjectionUpdateBatch updateBatch, IAggregationRuntime <TDoc, TId> runtime, DocumentStore store, EventRangeGroup parent) { _session = new ProjectionDocumentSession(store, updateBatch, new SessionOptions { Tracking = DocumentTracking.None, Tenant = Tenant }); _builder = new ActionBlock <EventSlice <TDoc, TId> >(async slice => { if (parent.Cancellation.IsCancellationRequested) { return; } await shardAgent.TryAction(async() => { await runtime.ApplyChangesAsync(_session, slice, parent.Cancellation, ProjectionLifecycle.Async).ConfigureAwait(false); }, parent.Cancellation, @group: parent, logException: (l, e) => { l.LogError(e, "Failure trying to build a storage operation to update {DocumentType} with {Id}", typeof(TDoc).FullNameInCode(), slice.Id); }, actionMode: GroupActionMode.Child).ConfigureAwait(false); }, new ExecutionDataflowBlockOptions { CancellationToken = parent.Cancellation, }); await processEventSlices(shardAgent, runtime, store, parent.Cancellation).ConfigureAwait(false); var builder = Volatile.Read(ref _builder); if (builder != null) { builder.Complete(); await builder.Completion.ConfigureAwait(false); } }
public override Task ConfigureUpdateBatch(IShardAgent shardAgent, ProjectionUpdateBatch batch, EventRangeGroup eventRangeGroup) { throw new NotSupportedException(); }
public override Task ConfigureUpdateBatch(IShardAgent shardAgent, ProjectionUpdateBatch batch, EventRangeGroup eventRangeGroup) { throw new System.NotImplementedException(); }