private void Work() { var token = _cancellationTokenSource.Token; while (!token.IsCancellationRequested) { ProperEventDataBatch batch = null; try { batch = _batches.Take(token); Commit(batch); } catch (OperationCanceledException tce) { // CANNOT CATCH - I KNOW // ignore } catch (Exception e) { if (batch != null && batch.RetryCount++ < 3) { _batches.Add(batch); } _settings.Logger(TraceLevel.Error, e.ToString()); } } }
private void Commit(ProperEventDataBatch batch) { if (batch.Count > 0) { _settings.Logger(TraceLevel.Verbose, $"{Name}: About to commit batch of size: {batch.CurrentSize}"); _sender.SendBatchAsync(batch.EventData).GetAwaiter().GetResult(); // no point in doing async, dedicated thread would be waiting anyway _settings.Logger(TraceLevel.Verbose, $"{Name}: Successfully sent batch. {_batches.Count} batches left"); } }
public PartitionCommitter(IPartitionSenderWrapper sender, DispatchSettings settings) { _sender = sender; _worker = new Thread(Work); _worker.IsBackground = settings.UseBackgroundThreads; _worker.Start(); _currentBatch = new ProperEventDataBatch(settings.MaxBatchSize); _settings = settings; }
private bool RebatchIfConditionMet(Func <bool> predicate, Action doIfRebatch = null) { if (predicate()) { lock (_lock) { if (predicate()) { _lastSent = DateTimeOffset.Now; _batches.Add(_currentBatch); _currentBatch = new ProperEventDataBatch(_settings.MaxBatchSize); if (doIfRebatch != null) { doIfRebatch(); } return(true); } } } return(false); }