private async Task PublishAsync( IEnumerable <LiteDBChunk> chunks, long start, ISubscription subscription, bool broadcastPosition, CancellationToken cancellationToken) { await subscription.OnStartAsync(start).ConfigureAwait(false); long positionOrIndex = 0; try { foreach (var chunk in chunks) { cancellationToken.ThrowIfCancellationRequested(); positionOrIndex = broadcastPosition ? chunk.Position : chunk.Index; if (chunk.Payload != null) { chunk.Payload = _options.PayloadSerializer.Deserialize((string)chunk.Payload); } var ok = await subscription.OnNextAsync(chunk).ConfigureAwait(false); if (!ok) { await subscription.StoppedAsync(positionOrIndex).ConfigureAwait(false); return; } } } catch (TaskCanceledException ex) { _logger.LogWarning($"PushToSubscriber: {ex.Message}.\n{ex.StackTrace}"); await subscription.StoppedAsync(positionOrIndex).ConfigureAwait(false); } catch (Exception e) { _logger.LogError($"Error During PushToSubscriber: {e.Message}.\n{e.StackTrace}"); await subscription.OnErrorAsync(positionOrIndex, e).ConfigureAwait(false); } await subscription.CompletedAsync(positionOrIndex).ConfigureAwait(false); }
public Task <bool> OnNextAsync(IChunk chunk) { _logger.LogDebug("OnNext {Position}", chunk.Position); if (chunk.Position != Position + 1) { if (_stopOnHole) { RetriesOnHole++; _logger.LogDebug("Hole detected on {Position} - {Retries}", chunk.Position, RetriesOnHole); return(Task.FromResult(false)); } _logger.LogWarning("Skipping hole on {Position}", chunk.Position); } RetriesOnHole = 0; _stopOnHole = true; Position = chunk.Position; Processed++; return(_subscription.OnNextAsync(chunk)); }
public Task <bool> OnNextAsync(IChunk chunk) { _logger.LogDebug("OnNext {Position}", chunk.Position); //Wait for holes if this commit is not sequential and it is greater that starting //commit to sequence stream. if (chunk.Position != Position + 1 && chunk.Position > _positionToStartSequencing) { if (_stopOnHole) { RetriesOnHole++; _logger.LogDebug("Hole detected on {Position} - {Retries}", chunk.Position, RetriesOnHole); return(Task.FromResult(false)); } _logger.LogWarning("Skipping hole on {Position}", chunk.Position); } RetriesOnHole = 0; _stopOnHole = true; Position = chunk.Position; Processed++; return(_subscription.OnNextAsync(chunk)); }