public async Task <long?> CountStreamRemainingEventsAsync( StreamCoordinates coordinates, StreamShardingSettings shardingSettings, CancellationToken cancellationToken = default) { try { var endCoordinates = await SeekToEndAsync(shardingSettings, cancellationToken).ConfigureAwait(false); var distance = coordinates.DistanceTo(endCoordinates); log.Debug( "Stream remaining events: {Count}. Current coordinates: {CurrentCoordinates}, end coordinates: {EndCoordinates}.", distance, coordinates, endCoordinates); return(distance); } catch (Exception e) { log.Warn(e, "Failed to count remaining events."); return(null); } }
public void Distance_should_work_correctly() { var a = new StreamCoordinates( new[] { new StreamPosition { Partition = 0, Offset = 1 }, new StreamPosition { Partition = 1, Offset = 100 } }); var b = new StreamCoordinates( new[] { new StreamPosition { Partition = 1, Offset = 200 }, new StreamPosition { Partition = 2, Offset = 2 } }); a.DistanceTo(b).Should().Be(102); b.DistanceTo(a).Should().Be(-99); }
private double?CountStreamRemainingEvents() { if (coordinates == null) { return(null); } var end = SeekToEndAsync(shardingSettings).GetAwaiter().GetResult(); var distance = coordinates.DistanceTo(end); log.Info( "Consumer progress: events remaining: {EventsRemaining}. Current coordinates: {CurrentCoordinates}, end coordinates: {EndCoordinates}.", distance, coordinates, end); return(distance); }