Interface IProjectionProgress
- Namespace
- Stratara.Abstractions.Projections
- Assembly
- Stratara.Abstractions.dll
Lets a host wait until a projection that reads the store from a checkpoint has applied what was committed: take a StoreMark once the write has committed, then wait for the projection to reach it before reading its read model.
public interface IProjectionProgress
- Extension Methods
Examples
await mediator.HandleAsync(command, cancellationToken);
var mark = await progress.MarkAsync([command.OrderId], cancellationToken);
var result = await progress.WaitAsync(typeof(OrdersProjection), mark, TimeSpan.FromSeconds(5), cancellationToken);
if (!result.IsReached)
{
// refuse with "try again", or answer without the read
}
Methods
MarkAsync(IEnumerable<Guid>, CancellationToken)
Takes a mark that covers every entry committed to streamIds at the time of the call, and
constrains only the partitions those streams fall into: a wait for it is not held up by any other partition. Take
it after the commit whose effect the host wants to read; a decision that needs everything committed, across
streams the host did not write, takes MarkAsync(CancellationToken) instead.
Task<StoreMark> MarkAsync(IEnumerable<Guid> streamIds, CancellationToken cancellationToken = default)
Parameters
streamIdsIEnumerable<Guid>The streams the host committed to.
cancellationTokenCancellationTokenPropagated to the store.
Returns
- Task<StoreMark>
The mark, to be passed back to WaitAsync(string, StoreMark, TimeSpan, CancellationToken).
Remarks
The default answers MarkAsync(CancellationToken), which covers more and so keeps the promise; an implementation that knows its partitions narrows it.
Exceptions
- ArgumentNullException
streamIdsis null.- ArgumentException
streamIdsnames no stream (the framework's implementation).
MarkAsync(CancellationToken)
Takes a mark that covers every entry committed at the time of the call, in every partition — an entry that is committed while another write is still open included. An entry whose transaction commits afterwards is not covered.
Task<StoreMark> MarkAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenPropagated to the store.
Returns
- Task<StoreMark>
The mark, to be passed back to WaitAsync(string, StoreMark, TimeSpan, CancellationToken).
WaitAsync(string, StoreMark, TimeSpan, CancellationToken)
Waits until the projection has applied every entry mark covers, in every partition, or until
timeout has passed. A partition stopped at an entry does not end the wait early, because a
retry may still apply the entry in time; a rebuild or a full replay during the wait is waited through.
Task<ProjectionWaitResult> WaitAsync(string projectionName, StoreMark mark, TimeSpan timeout, CancellationToken cancellationToken = default)
Parameters
projectionNamestringThe projection, by the name the framework gives it.
markStoreMarkA mark taken with MarkAsync(CancellationToken) or MarkAsync(IEnumerable<Guid>, CancellationToken).
timeoutTimeSpanHow long to wait at most; Zero answers without waiting.
cancellationTokenCancellationTokenEnds the wait without an answer.
Returns
- Task<ProjectionWaitResult>
Reached once the projection has applied the mark's entries; otherwise why it has not, with the partitions that are behind.
Exceptions
- InvalidOperationException
No projection of that name is registered.
- ArgumentOutOfRangeException
timeoutis negative.- OperationCanceledException
cancellationTokenwas cancelled.
WaitAsync(Type, StoreMark, TimeSpan, CancellationToken)
Waits until the projection of projectionType has applied every entry mark
covers; otherwise as WaitAsync(string, StoreMark, TimeSpan, CancellationToken).
Task<ProjectionWaitResult> WaitAsync(Type projectionType, StoreMark mark, TimeSpan timeout, CancellationToken cancellationToken = default)
Parameters
projectionTypeTypeThe type of a registered projection.
markStoreMarkA mark taken with MarkAsync(CancellationToken) or MarkAsync(IEnumerable<Guid>, CancellationToken).
timeoutTimeSpanHow long to wait at most; Zero answers without waiting.
cancellationTokenCancellationTokenEnds the wait without an answer.
Returns
- Task<ProjectionWaitResult>
Whether the projection reached the mark, and if not, why and in which partitions.
Exceptions
- InvalidOperationException
No projection of that type is registered.
- ArgumentOutOfRangeException
timeoutis negative.- OperationCanceledException
cancellationTokenwas cancelled.