예제 #1
0
        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());
                }
            }
        }
예제 #2
0
 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");
     }
 }
예제 #3
0
 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;
 }
예제 #4
0
        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);
        }