public long GetCheckpoint() { var bufferCheckpoint = _bufferCheckpointManager.GetCheckpoint(); var targetCheckpoint = _targetCheckpointManager.GetCheckpoint(); return(Math.Max(bufferCheckpoint, targetCheckpoint)); }
public void ShouldThrowIfCancellationRequestedWhenGettingCheckpoint() { // Arrange using var cancellationSource = new CancellationTokenSource(); var token = cancellationSource.Token; cancellationSource.Cancel(); // Act/Assert Should.Throw <TaskCanceledException>(async() => await _sut.GetCheckpoint(CheckpointName, token).ConfigureAwait(false)); }
/// <inheritdoc cref="IEventObserver.InitialiseObserver" /> public async Task InitialiseObserver(CancellationToken cancellationToken = default) { Logger.LogInformation("{observerType} is initialising...", GetType().FullName); _checkpoint = await _checkpointManager.GetCheckpoint(CheckpointName, cancellationToken) .ConfigureAwait(false); var globalCheckpoint = await _getGlobalCheckpoint(cancellationToken).ConfigureAwait(false); if (_checkpoint != globalCheckpoint) { await CatchUp(cancellationToken).ConfigureAwait(false); } }
public BufferedCheckpointManager(ICheckpointManager bufferCheckpointManager, ICheckpointManager targetCheckpointManager, int bufferInterval) { Guard.ArgumentNotNull(bufferCheckpointManager, nameof(bufferCheckpointManager)); Guard.ArgumentNotNull(targetCheckpointManager, nameof(targetCheckpointManager)); _bufferCheckpointManager = bufferCheckpointManager; _targetCheckpointManager = targetCheckpointManager; _bufferInterval = bufferInterval; var bufferCheckpoint = _bufferCheckpointManager.GetCheckpoint(); var targetCheckpoint = _targetCheckpointManager.GetCheckpoint(); if (bufferCheckpoint > targetCheckpoint) { _targetCheckpointManager.SaveCheckpoint(bufferCheckpoint); } _timer = new PeriodicAction(SendBufferToTarget, bufferInterval); }