Exemplo n.º 1
0
        public async Task SetCheckpointAsync(IEventMessage eventArgs, IEnumerable <KeyValuePair <Metric, double> > metrics = null)
        {
            EnsureArg.IsNotNull(eventArgs);
            EnsureArg.IsNotNullOrWhiteSpace(eventArgs.PartitionId);

            try
            {
                var partitionId = eventArgs.PartitionId;
                var checkpoint  = new Checkpoint
                {
                    LastProcessed = eventArgs.EnqueuedTime,
                    Id            = partitionId,
                    Prefix        = _blobPath,
                };

                await UpdateCheckpointAsync(checkpoint);

                _logger.LogMetric(EventMetrics.EventWatermark(partitionId), 1);

                if (metrics != null)
                {
                    foreach (var metric in metrics)
                    {
                        _logger.LogMetric(metric.Key, metric.Value);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(new StorageCheckpointClientException($"Unable to set checkpoint. {ex.Message}", ex));
            }
        }
        public async Task SetCheckpointAsync(IEventMessage eventArgs)
        {
            EnsureArg.IsNotNull(eventArgs);
            EnsureArg.IsNotNullOrWhiteSpace(eventArgs.PartitionId);

            try
            {
                var partitionId = eventArgs.PartitionId;
                var checkpoint  = new Checkpoint();
                checkpoint.LastProcessed = eventArgs.EnqueuedTime;
                checkpoint.Id            = partitionId;
                checkpoint.Prefix        = _blobPath;

                _checkpoints[partitionId] = checkpoint;
                var count = _lastCheckpointTracker.AddOrUpdate(partitionId, 1, (key, value) => value + 1);

                if (count >= _lastCheckpointMaxCount)
                {
                    await PublishCheckpointAsync(partitionId);

                    _log.LogMetric(EventMetrics.EventWatermark(partitionId, eventArgs.EnqueuedTime.UtcDateTime), 1);
                    _lastCheckpointTracker[partitionId] = 0;
                }
            }
#pragma warning disable CA1031
            catch (Exception ex)
#pragma warning restore CA1031
            {
                _log.LogError(new Exception($"Unable to set checkpoint. {ex.Message}"));
            }
        }
Exemplo n.º 3
0
        public async Task SetCheckpointAsync(IEventMessage eventArgs, IEnumerable <KeyValuePair <Metric, double> > metrics = null)
        {
            EnsureArg.IsNotNull(eventArgs);
            EnsureArg.IsNotNullOrWhiteSpace(eventArgs.PartitionId);

            try
            {
                var partitionId = eventArgs.PartitionId;
                var checkpoint  = new Checkpoint
                {
                    LastProcessed = eventArgs.EnqueuedTime,
                    Id            = partitionId,
                    Prefix        = _blobPath,
                };

                _checkpoints[partitionId] = checkpoint;
                var count = _lastCheckpointTracker.AddOrUpdate(partitionId, 1, (key, value) => value + 1);

                if (metrics != null)
                {
                    _postCheckpointMetrics.TryGetValue(partitionId, out var partitionExists);

                    if (partitionExists == null)
                    {
                        _postCheckpointMetrics[partitionId] = new List <KeyValuePair <Metric, double> >();
                    }

                    foreach (var metric in metrics)
                    {
                        _postCheckpointMetrics[partitionId].Add(metric);
                    }
                }

                if (count >= _lastCheckpointMaxCount)
                {
                    await PublishCheckpointAsync(partitionId);

                    _logger.LogMetric(EventMetrics.EventWatermark(partitionId), 1);
                    _lastCheckpointTracker[partitionId] = 0;

                    _postCheckpointMetrics.TryGetValue(partitionId, out var postCheckpointMetrics);
                    postCheckpointMetrics?.ForEach(m =>
                    {
                        _logger.LogMetric(m.Key, m.Value);
                    });

                    postCheckpointMetrics?.Clear();
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(new StorageCheckpointClientException($"Unable to set checkpoint. {ex.Message}", ex));
            }
        }